简体   繁体   中英

Can't run “rake db:create”

I try to setup a postgres DB for my rails project but everytime I run the command:

rake db:create

I get the error

    FATAL:  role "myrole" does not existCouldn't create database for{"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, 
"database"=>"web_db", "username"=>"myrole", "password"=>"password", "host"=>"localhost"}                                                            rake aborted!  

When I login into my web_db database with the user myrole and type in \\du it showsme all the roles including myrole! This role has also Superuser, create Role and createDB attributes.

I have no idea whats wrong..

Edit my database.yml

development:                                                                                                           
  adapter: postgresql                                                                                                  
  encoding: unicode                                                                                                    
  database: myapp_development                                                                                          
  pool: 5                                                                                                              
  username: myrole                                                                                                    
  password: password                                                                                                  
  host: localhost                                                                                                                                                                                                                         
test:                                                                                                                  
  adapter: postgresql                                                                                                  
  encoding: unicode                                                                                                    
  database: myapp_test                                                                                                 
  pool: 5                                                                                                              
  username: myrole                                                                                                    
  password: password                                                                                                  
  host: localhost 

What I did wrong:

I used su postgres to open psql and create roles.

What I had to do is to login from my user with the command:

psql -h localhost -d web_db -U postgres or sudo -u postgres psql

Then I had to create a role and asign rights:

CREATE ROLE myrole;

ALTER ROLE myrole WITH login;

ALTER ROLE myrole WITH CREATEDB;

ALTER ROLE myrole WITH PASSWORD 'password';

then I could run the command : rake db:setup

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