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

v6ylcynt  于 12个月前  发布在  Ruby
关注(0)|答案(3)|浏览(154)

当我运行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}" %>

u91tlkcl

u91tlkcl1#

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

RAILS_ENV=test bundle exec rake db:test:prepare

字符串

4xy9mtcn

4xy9mtcn2#

参考这可能是相同的问题rake db:test:load,undefined method `[]' for nil:NilClass
或者试试这个

RAILS_ENV=test rake db:setup

字符串

mrfwxfqh

mrfwxfqh3#

当我尝试运行一个使用Rails.application.credentials的初始化器时,我在github操作中得到了这个错误
这个错误的原因是因为我忘记了给github action工作流给予我的RAILS_MASTER_KEY,所以github action无法获得在初始化器中使用的凭据。
一旦我added the RAILS_MASTER_KEY to the github repo,它工作。

相关问题