所以我一直在寻找各地试图找到解决方案,到目前为止我没有运气。我是铁轨上的红宝石,所以我很可能会遗漏一些基本的东西,或者正在寻找解决方案的错误位置,所以我想我只是问。我有一个rails API,我从我的组织分叉,我想在本地运行它。我在终端
中遇到了这条线bundle exec rake create:db
并且出现了这个错误,我真的不知道该怎么做:/如果这个问题已经得到解答,请指出我在那里,我会弄清楚!谢谢。
Admins-MacBook-Pro:environments nathanshanko$ bundle exec rake db:create
(in /Users/nathanshanko/Desktop/git-repos/voke_api)
rake aborted!
KeyError: Cannot load `Rails.application.database_configuration`:
key not found: "DB_ENV_POSTGRESQL_USER"
(erb):7:in `fetch'
(erb):7:in `'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/application/configuration.rb:104:in `database_configuration'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:41:in `block (3 levels) in '
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `'
KeyError: key not found: "DB_ENV_POSTGRESQL_USER"
(erb):7:in `fetch'
(erb):7:in `'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/railties-4.2.6/lib/rails/application/configuration.rb:104:in `database_configuration'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:41:in `block (3 levels) in '
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/nathanshanko/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
这是我的database.yml文件
common: &common
adapter: postgresql
encoding: utf8
reconnect: true
pool: <%= ENV['DB_ENV_POSTGRESQL_POOL'] || 5 %>
database: <%= ENV['DB_ENV_POSTGRESQL_DB'] || 'voke_api' %>
username: <%= ENV.fetch('DB_ENV_POSTGRESQL_USER') %>
password: <%= ENV['DB_ENV_POSTGRESQL_PASS'] %>
host: <%= ENV.fetch('DB_PORT_5432_TCP_ADDR') %>
port: <%= ENV['DB_PORT_5432_TCP_PORT'] %>
development:
<<: *common
production:
<<: *common
staging:
<<: *common
test:
<<: *common
答案 0 :(得分:1)
听起来你错过了一些定义数据库凭据的env变种。您需要设置它们(通过命令行,或类似.env
或application.yml
文件,具体取决于您的项目设置。
DB_ENV_POSTGRESQL_USER
导致的错误归因于ENV.fetch
,如果找不到密钥则会引发IndexError
。您可能还缺少其他环境变量,但ENV['xyz']
将无声地失败而不会出现任何错误。