运行rake db时,我总是遇到以下错误:test:prepare。什么可以导致这个? rake db:create工作得很好。
Adam-MacBook-Pro:katy adam$ bundle exec rake db:test:prepare
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Users/adam/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:163:in `purge'
/Users/adam/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:356:in `block (3 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:362:in `block (3 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/Users/adam/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
的database.yml
<%= Rails.env %>:
adapter: mysql2
encoding: utf8
pool: <%= ENV['DB_POOL'] || 5 %>
username: <%= ENV['DB_USER'] || 'root' %>
password: <%= ENV['DB_PASSWORD'] || nil %>
timeout: <%= ENV['DB_TIMEOUT'] || 5000 %>
host: <%= ENV['DB_HOST'] || 'localhost' %>
port: <%= ENV['DB_PORT'] || 3306 %>
database: <%= ENV['DB_NAME'] || "website#{Rails.env}" %>
答案 0 :(得分:4)
运行rake命令时尝试指定RAILS_ENV
:
RAILS_ENV=test bundle exec rake db:test:prepare
答案 1 :(得分:2)
参考这可能是同一个问题rake db:test:load, undefined method `[]' for nil:NilClass
或试试这个
RAILS_ENV=test rake db:setup