Ruby ActiveRecord配置未在db:create上指定适配器
这很奇怪。我肯定是在指定适配器,它甚至在rake任务的顶行打印散列,并将Ruby ActiveRecord配置未在db:create上指定适配器,ruby,activerecord,Ruby,Activerecord,这很奇怪。我肯定是在指定适配器,它甚至在rake任务的顶行打印散列,并将放入。db:迁移也可以 $ rake db:create {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"craigslist_development", "pool"=>5, "username"=>"root", "password"=>"splitzo", "hos
放入。db:迁移也可以
$ 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的建立连接,第二次它没有得到散列。我添加了一些调试代码
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中的逻辑问题?正如@Taryn East所说,您必须将RAILS_ENV传递给rake
rake db:create RAILS\u ENV=development
应该可以做到这一点。您指定了要使用哪些RAILS\u ENV吗?您可以发布您的database.yml吗?