2016-01-24 25 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