【发布时间】:2019-02-22 22:53:10
【问题描述】:
我已经为这个问题搜索了几个小时的所有解决方案,但我无法让它工作。
我有一个 Rails 应用程序,我正在尝试将其部署到 heroku,但是当我运行 heroku run rake db:migrate 时,我收到此错误:
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 validator 来验证我的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 } %>
我该如何解决这个问题?我不知道。
【问题讨论】:
-
第七行是开发部分的`adapter: postgresql`,对吧?你确定这是
adapter之前的两个空格(没有别的)吗?cat -vet database.yml说什么? -
原因可能在编码上。例如,可能有 BOM。如果是 Windows,您将看不到它。创建一个 UTF-8 格式的新文档并重复。
-
您是否能够将您的应用程序部署到heroku?你有数据库配置吗?如果您运行
heroku config --app <yourappname>,您会看到DATABASE_URL吗? -
是的,我的意思是替换为新的
database.yml。要指定编码,您可以选择使用 UTF-8 保存。例如,您可以在 Sublime 或其他文本编辑器中执行此操作 -
没有 BOM、不间断空格或其他符号?我建议使用手动输入制作新文件。
标签: ruby heroku syntax-error yaml ruby-on-rails-5.2