Gustavo Luigi
Gustavo Luigi

Reputation: 33

YAML syntax error when running "heroku run rake db:migrate" on my Rails app

I've searched every solve for this problem for hours but I just can't get it to work.

I have a Rails app and I'm trying to deploy it to heroku, but when I run heroku run rake db:migrate, I get this error:

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

I already used a YAML validator to validate my database.yml, but it still does not work. Here is how it looks like:

# 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 } %>

How can I solve this? I have no clue.

Upvotes: 2

Views: 223

Answers (3)

Gustavo Luigi
Gustavo Luigi

Reputation: 33

I just solved it starting over the step by step to deploy the App in Heroku.

Upvotes: 0

mechnicov
mechnicov

Reputation: 15288

Use single quotes in line

  password: <%= ENV['CHAMADA_DATABASE_PASSWORD'] %>

You have used double quotes, so it was like:

"<%= ENV[" CHAMADA_DATABASE_PASSWORD "] %>"

That's why error.

Upvotes: 1

lacostenycoder
lacostenycoder

Reputation: 11226

UPDATE: I have not worked on Heroku for a while, however I found an old project with these notes in my database.yml file:

# 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'] %>

You will probably need to make sure you have the environment variables set correctly. Check by running heroku config --app <your-app-name>

You should not need ----

If you're going to set default you might as well use it to not repeat yourself. And also use single quotes and remove string interpolation. You can add blank lines between each group.

default: &default 
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>

development:
  <<: *default 
  database: chamada_development
  password: <%= ENV['CHAMADA_DATABASE_PASSWORD'] %>
  username: chamada

production: 
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>

test:
  <<: *default
  adapter: postgresql
  database: chamada_test

Upvotes: 0

Related Questions