Setting up a second Rails app locally with PG

94 Views Asked by At

I already have a Rails app, successfully working with Postgres.app.

I don't even remember what I did to get the first database created and connected to Rails, but it works and this is what I have in database.yml

development:
  adapter: postgresql
  database: gnossy_development
  pool: 5
  timeout: 5000

Now for my second Rails app I've created the app with

rails new my_app --database=postgresql --skip-test-unit

And Rails created this for me in database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: my_app_development

What would I need to do, to get my second app connected with a PG db?

rake db:create:all results in "FATAL: role "my_app" does not exist"

1

There are 1 best solutions below

2
On

The error you are getting is a postgres error.

"FATAL:  role "my_app" does not exist"

When you run migrations the app tries to log into the database to perform the migrations.

This error is telling you that in the database you don't have a role called "my_app"

If you would like to check if this is true log into your postgres database:

From console:

psql

Once you are in, check your roles:

\du

This command will return a relation of your roles with their permissions.

To fix this in your rails app try adding user and password credentials with PG permissions to database.yml

username: your_user
password: your_pasword