gpt4 book ai didi

ruby-on-rails - rake 数据库 :create gives undefined method `[]' for nil:NilClass error

转载 作者:搜寻专家 更新时间:2023-10-30 20:40:34 24 4
gpt4 key购买 nike

Postgres 9.3, ruby 2.1.0

rake db:create 没有创建测试数据库。我已经有一个生产数据库。我尝试使用 RAILS_ENV=test rake db:create 来强制执行它,但它返回“未配置测试数据库。

我的database.yml ->

development:
adapter: postgresql
  database: app_prod
  host: localhost

test: &test
  adapter: postgresql
  database: app_test
  host: localhost

cucumber:
<<: *test

production:
  adapter: postgresql
 database: app_prod
  host: localhost

这样就配置好了。我也尝试只使用控制台 createdb app_test 来创建我的测试数据库,但是当我尝试运行 rake db:test:prepare 时,我收到了同样的错误。

有人有什么想法吗?

这是 --trace on db:create:all

** Invoke db:create:all (first_time)

** Invoke db:load_config (first_time)

** Execute db:load_config

** Execute db:create:all

rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:189:in `block in each_local_configuration'

这是对 db:test:prepare 的跟踪

** Invoke db:test:prepare (first_time)

** Invoke db:load_config (first_time)

** Execute db:load_config

** Execute db:test:prepare

** Invoke db:test:load (first_time)

** Invoke db:test:purge (first_time)

** Invoke environment (first_time)

** Execute environment

** Invoke db:load_config

** Execute db:test:purge
rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:137:in `purge'

最佳答案

尝试在控制台中运行它

ActiveRecord::Base.configurations

你应该得到你的数据库配置。

此方法中的第 3 行(github 中的第 189 行)在您的情况下失败,因为配置为零

def each_local_configuration
ActiveRecord::Base.configurations.each_value do |configuration|
next unless configuration['database']

if local_database?(configuration)
yield configuration
else
$stderr.puts "This task only modifies local databases. #{configuration['database']} is on a remote host."
end
end
end

关于ruby-on-rails - rake 数据库 :create gives undefined method `[]' for nil:NilClass error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com