Rails アプリで「heroku run rake db:merge」を実行すると YAML 構文エラーが発生する
概要
この問題のすべての解決策を何時間も探しましたが、うまくいきません。
Rails アプリがあり、それを Heroku にデプロイしようとしていますが、heroku run rake db:merge を実行すると、次のエラーが発生します。
rake aborted!
YAML syntax error occurred while parsing /app/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): did not find expected key while parsing a block mapping at line 7 column 3
すでに YAML バリデーターを使用して、database.yml を検証しましたが、まだ機能しません。これは次のようになります。
# database.yml
---
default:
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
adapter: postgresql
database: chamada_development
encoding: unicode
password: "<%= ENV['CHAMADA_DATABASE_PASSWORD'] %>"
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: chamada
production:
adapter: postgresql
database: chamada_production
encoding: unicode
password: "<%= ENV['CHAMADA_DATABASE_PASSWORD'] %>"
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: chamada
test:
adapter: postgresql
database: chamada_test
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
どうすればこれを解決できますか?私は見当もつかない。
解決策
行内で一重引用符を使用する
password: <%= ENV['CHAMADA_DATABASE_PASSWORD'] %>
二重引用符を使用しているため、次のようになります。
“<%= ENV[” CHAMADA_DATABASE_PASSWORD ”] %>”
だからこそエラーが出る。