Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres db not working on Heroku

I've spend several hours figuring out how to get my database up and running. I created a new rails app and wanted to deploy it to heroku. I followed the instructions from heroku (to switch from sqlite3 -> postgresql) but it just doesn't work.

This is in my database.yml file:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test

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

I can't create or seed any data in the database. Sometimes it executes the db:migrate, but even then it doesn't create anything. This is what I get when running:

heroku run rake db:create

FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.

Does anyone has an idea on how to solve this? I don't have a clue anymore ...

Thanks!

like image 518
crievino Avatar asked Jan 25 '26 14:01

crievino


1 Answers

By default you don't need to create a db on heroku. Just run heroku run rails db:migrate and rest of the stuff will be handled by heroku itself.

Also your database.yml should be changed to following for Production env.

production:
  <<: *default
  database: myapp_production
  username: myapp
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Also your rails app is by default assigned with a Postgres addon. You can check this by running command heroku addons in the console.

Source -

  1. Heroku Getting Started Guide
  2. Heroku Postgres Addon Guide
like image 102
Swaps Avatar answered Jan 27 '26 02:01

Swaps



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!