ActiveRecord配置未在db:create上指定适配器

时间:2013-09-23 23:27:57

标签: ruby activerecord

这很奇怪。我肯定在指定适配器,它甚至在rake任务的顶行用puts打印出散列。 db:migrate也可以。

$ rake db:create
{"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false,     "database"=>"craigslist_development", "pool"=>5, "username"=>"root", "password"=>"splitzo",   "host"=>"localhost"}
rake aborted!
database configuration does not specify adapter

任何想法?

如果您需要更多信息,请与我们联系。

更新

当我运行 rake db:migrate

时,我确信环境设置正确

我注意到它正在运行ActiveRecord的establish_connection两次,第二时间它没有得到哈希值。我添加了一些调试代码

spec = spec.symbolize_keys
puts 'test:' + spec.key?(:adapter).to_s

我得到了这个:

{"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"appname_development", "pool"=>5, "username"=>"user", "password"=>"password", "host"=>"localhost"} (just prints hash object)

test:true (first time)
test:false (second time)
rake aborted!
database configuration does not specify adapter

它基本上只是这个,因为它适用于其他任务,我认为格式很好,没有奇怪的空白问题等:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: appname_development
  pool: 5
  username: user
  password: password
  host: localhost

我的Rakefile中的逻辑一定是个问题吗?

1 个答案:

答案 0 :(得分:1)

正如@Taryn East所说,你必须传递RAILS_ENV来耙。

rake db:create RAILS_ENV=development应该可以解决问题。

相关问题