当我运行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}" %>
型
3条答案
按热度按时间u91tlkcl1#
尝试在运行rake命令时指定
RAILS_ENV
:字符串
4xy9mtcn2#
参考这可能是相同的问题rake db:test:load,undefined method `[]' for nil:NilClass
或者试试这个
字符串
mrfwxfqh3#
当我尝试运行一个使用
Rails.application.credentials
的初始化器时,我在github操作中得到了这个错误这个错误的原因是因为我忘记了给github action工作流给予我的
RAILS_MASTER_KEY
,所以github action无法获得在初始化器中使用的凭据。一旦我added the
RAILS_MASTER_KEY
to the github repo,它工作。