kaizenx
kaizenx

Reputation: 425

FATAL: role "root" does not exist, rails only on website, rails console works

So I inherited this mess of a rails project.

I am migrating the DB from mysql to postgres.

I am now encountering this error when trying to open my test webpage

ActiveRecord::NoDatabaseError at /test FATAL: role "root" does not exist Run $ bin/rake db:create db:migrate to create your database

This error occurs throughout the entire site.

BUT the rails console can connect to the DB and I can create objects in the DB via console.

this is my database.yml

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

development:
  <<: *default
  database: aas_development

test:
  <<: *default
  database: aas_test

production:
  <<: *default
  database: aas_production
  username: aas
  password: <%= ENV['ASS_DATABASE_PASSWORD'] %>

Upvotes: 0

Views: 1361

Answers (1)

Akshay Borade
Akshay Borade

Reputation: 2472

Create database user(Role):

Postgres uses the concept of roles to distinguish the variety of users that can connect to a database. When it is first installed on a server, the default postgres user is actual named “postgres”.

To create custom user, first switch into the default user:

sudo su – postgres

Now create new role(user) in PostgreSQL system :

createuser

It will propmpt you as follow :

Enter name of role to add: newuser

Shall the new role be a superuser? (y/n) y

If you want to set password for newly created Role(User) then command should be:

createuser --pwprompt

and Your database.yml should be like this.

default: &default
 adapter: postgresql
 pool: 5
 timeout: 5000
 username: your_username
 password: your_password

development:
 <<: *default
 database: db_name_development

test:
 <<: *default
 database: db_name_test

production:
 <<: *default
 database: db_name

Upvotes: 0

Related Questions