Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating user for postgresql on rails

I chose postgresql for my database for rails but i ran into an apparently common error where 'FATAL: role "app" does not exist' when i try to run rake db:create:all. I found two solutions but im not sure which one is the right one to use. One website says to

su -  
su - postgres
createuser -s Application
exit
exit  

while the other says to

su - postgres
create role myapp with createdb login password 'password1'

what's the difference between the two? and which one should i use?

like image 658
jsanch16 Avatar asked Oct 29 '25 03:10

jsanch16


1 Answers

You should use this for the development environment only

Login in postgres console:

$> sudo -u postgres psql

create user with name rails and password:

=# create user rails with password 'password';  

make user rails superuser:

=# alter role rails superuser createrole createdb replication; 

create database projectname with owner rails:

=# create database projectname owner rails;

in database.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: projectname
  pool:
  username: rails
  password: password
like image 52
Philidor Avatar answered Oct 31 '25 18:10

Philidor