简体   繁体   中英

rake test prepare: NoMethodError: undefined method `[]' for nil:NilClass

I always get the following error when I run rake db:test:prepare. what can cause this? rake db:create works fine.

 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}" %>

运行rake命令时,尝试指定RAILS_ENV

RAILS_ENV=test bundle exec rake db:test:prepare

refer this might be the same issue rake db:test:load, undefined method `[]' for nil:NilClass

or try this

RAILS_ENV=test rake db:setup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM