2016-01-24 65 views
0

我一直在玩空间,并且不能在我的生活中使用我的Heroku应用程序来迁移数据库。我不断收到Heroku vs YAML - 有效的YAML不被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文件,并通过所有的人都被告知,他们是“有效”。

这里的编辑 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:[email protected]/somedatabase" 
# 
# You can use this database configuration with: 
# 
    production: 
    url: <%= ENV['DATABASE_URL'] %> 
# 
production: 
+0

线是不是你标记的代码行,但不是文件的最后一行。 –

+0

删除文件末尾的'production:'部分。你不需要它们。 Heroku在post commit hook中将生产数据库设置写入'database.yml'中。 – max

+0

您应该考虑使用环境变量“DATABASE_URL”而不是推送数据库配置。 – Arthur

回答

1

解析器错误是由于不一致的缩进。我建议你使用一个体面的文本编辑器,并使用2个空格来缩进块。

我不知道你用什么来验证没有捕获错误的YAML--复制粘贴到基于web的验证器并不能很好地工作。相反,你可以使用Ruby的YAML模块来解析文件:

# run `$ irb` from the root of project 
require 'yaml' 
YAML.parse(File.open('./config/development.rb')) 

而且Heroku的会写的生产设置到文件所以你不应该在你的database.yml文件production:部分。

这是一个正确的版本,它解析正确:62

# 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. 
+0

我会推荐[Atom](https://atom.io/)作为编辑器。它的自由和理解YAML和Ruby。而不是检查你的本地开发postgres设置,你可能想要使用env vars,以便其他开发者不必设置postgres来匹配你的设置。 – max