【问题标题】:Ruby on Rails "KeyError: key not found" when deploying with capistrano使用 capistrano 部署时,Ruby on Rails “KeyError:找不到密钥”
【发布时间】:2020-06-07 00:18:21
【问题描述】:

我正在尝试使用capistrano 部署我的rails 应用程序,但在db:migrate 之后我得到了

  01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
  01 rake aborted!
  01 KeyError: Cannot load database configuration:
  01 key not found: "APP_DATABASE_PASSWORD"
  01 (erb):54:in `fetch'
  01 (erb):54:in `<main>'
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application/configuration.rb:228:in `database_configuration'
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/railtie.rb:39:in `block (3 levels) in <class:Railti…
  01 /home/deploy/app/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
  01 /home/deploy/.rbenv/versions/2.6.3/bin/bundle:23:in `load'
  01 /home/deploy/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>'

但是我已经在我的 .bashrc 文件中设置了 APP_DATABASE_PASSWORD 并且已经获取了它。

这是我的database.yml

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV.fetch("APP_DATABASE_USERNAME") %>
  password: <%= ENV.fetch("APP_DATABASE_PASSWORD") %>
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *default
  database: app_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production
  username: app
  password: <%= ENV.fetch("APP_DATABASE_PASSWORD") %>

在我的.bashrc:

export APP_DATABASE_PASSWORD="SOME_PASSWORD"
export APP_DATABASE_USERNAME="SOME_USERNAME"

【问题讨论】:

标签: ruby-on-rails ruby capistrano


【解决方案1】:

在你的 .bashrc 中,如果你看到这一行;

[ -z "$PS1" ] && return

把你的出口放在上面。

【讨论】:

  • 我的.bashrc 中没有该行。就像这样PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  • 但我已经将case $- in *i*) ;; *) return;; esac 粘贴在该块上方,如this answer 中所述
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-15
  • 2015-11-11
  • 2021-02-01
相关资源
最近更新 更多