我整天都在玩太空,但在我的生命中,我不能让我的Heroku应用程序迁移数据库。我一直在
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 62 column 3
除了我通过三个不同的验证器运行我的YAML文件并且所有人都告诉他们它们是有效的&#39;之外,哪个都很好并且花花公子作为错误。
此处有已编辑的 YAML
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: coder-app_title
username: postgres
password: 123456
host: localhost
username: personal_username
password: personal_password
# 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 [[<< This is line 62.]]
database: coder-add_title_test
username: postgres
password: 123456
host: localhost
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
production:
url: <%= ENV['DATABASE_URL'] %>
#
production:
答案 0 :(得分:1)
解析器错误是由于不一致的缩进造成的。我建议你使用一个体面的文本编辑器并使用2个空格来缩进块。
我不知道你用什么来验证没有捕获错误的YAML - 将粘贴复制到基于Web的验证器并不能很好地工作。相反,您可以使用Ruby YAML模块来解析文件:
# run `$ irb` from the root of project
require 'yaml'
YAML.parse(File.open('./config/development.rb'))
此外,Heroku会将生产设置写入文件中,因此您的production:
文件中不应包含database.yml
部分。
这是一个正确解析的更正版本:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: coder-app_title
username: postgres
password: 123456
host: localhost
username: personal_username
password: personal_password
# 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: coder-add_title_test
username: postgres
password: 123456
host: localhost
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# NOTE. Heroku will write production settings in a post-commit hook. No configuration needed.