简体   繁体   中英

Ruby on Rails/Postgres - How can I create a new database for a user that doesn't exist?

I've cloned a repository, and set up everything via a virtual machine loaded with Ubuntu and using RVM. Everything regarding Ruby on Rails was installed via RVM.

My issue is that, my Ubuntu login is different to the user that I assume the data base wants. Example, my Ubuntu login is Matt, but when I start rails server and load into the localhost:3000, it is saying this:

ActiveRecord::NoDatabaseError
FATAL: role "James" does not exist 

I understand this is a postgres error, but what should I do now to make this work? I've search through the previous StackOverflow answers and the methods just don't work.

Eg. I've changed

local   all             postgres                                peer

to

local   all             postgres                                trust

Or using psql -h localhost -U postgres or sudo -u postgres createuser -s $(whoami); createdb $(whoami) sudo -u postgres createuser -s $(whoami); createdb $(whoami) and again, it doesn't work. The first command asks for a password, which I can't figure out.

You can change the user Rails uses to connect to PostgreSQL by editing <project_root>/config/database.yml ( source ).

Also, the reason your first psql command didn't work is -h localhost requires a host entry in pg_hba.conf , not local . You can omit the -h localhost for the local entry to take effect since the default is to connect via a local socket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM