【问题标题】:heroku: rake db:migrate fails with mongoDBheroku: rake db:migrate 使用 mongoDB 失败
【发布时间】:2012-11-26 06:37:34
【问题描述】:

运行 heroku run rake db:migrate 并得到错误:

Running `rake db:migrate` attached to terminal... up, run.9259
DEPRECATION WARNING: railtie_name is deprecated and has no effect. (called from <top (required)> at /app/config/application.rb:10)
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Quora::Application#task called at /app/vendor/bundle/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:214:in `initialize_tasks'
rake aborted!
Database should be a Mongo::DB, not NilClass.

本地一切运行良好。我有一个 mongoid.yml 文件,其中包含 mongo 的配置,并使用 mongohq 创建了一个 mongo db:

defaults: &defaults
  host: '127.0.0.1'
  autocreate_indexes: false
  allow_dynamic_fields: true
  include_root_in_json: false
  parameterize_keys: true
  persist_in_safe_mode: false
  raise_not_found_error: true
  reconnect_time: 3

development:
  <<: *defaults
  database: mydb_development

development_mongohq:
  <<: *defaults
  #use demo mongohq database for fast run
  uri: mongodb://user:pass@linus.mongohq.com:10016/app9861715

test:
  <<: *defaults
  database: quora_test

# set these environment variables on your prod server
production:
  <<: *defaults
  host: '127.0.0.1'
  database: mydb

我已尝试寻找解决方案或任何有关如何解决的方向,但均未成功。我做错了什么?

编辑:我将 include Rake::DSL 添加到我的 Rakefile 中,现在最初的警告消失了,但我仍然得到:

heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.4751
DEPRECATION WARNING: railtie_name is deprecated and has no effect. (called from <top (required)> at /app/config/application.rb:11)
rake aborted!
Database should be a Mongo::DB, not NilClass.

Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

【问题讨论】:

    标签: ruby-on-rails mongodb heroku mongohq


    【解决方案1】:

    我认为你不见了:

    adapter: mongodb
    

    这是我对 postgres database.yml 的设置:

    development: 
      adapter: postgresql
      encoding: unicode
      database: db
      pool: 50
      username: user
      password: pwd
      host: localhost
    

    你可能也想看看这篇文章:

    https://stackoverflow.com/a/6757749/169277

    【讨论】:

    • 嘿@ant 我相信 mongoid 是完全替代品而不是适配器
    猜你喜欢
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 2014-07-10
    • 2012-06-19
    • 1970-01-01
    • 2015-04-23
    • 2015-02-20
    相关资源
    最近更新 更多