Role does not exist and unable to create database when using PostgreSQL

后端 未结 3 2088
鱼传尺愫
鱼传尺愫 2020-12-07 07:45

I am using Heroku for my application and it requires PostgreSQL but you can still use SQLite3 for development. Since Heroku strongly advised against having 2 different datab

3条回答
  •  眼角桃花
    2020-12-07 08:31

    Add a username to your database.yml, might as well use your application's name (or some variant of the name) as the username, I'll use app_name as a placeholder:

    development:
      adapter: postgresql
      encoding: utf8
      database: app_development
      pool: 5
      username: app_name
      password:
    

    Then create the user (AKA "role") inside PostgreSQL using psql.exe:

    $ psql -d postgres
    postgres=# create role app_name login createdb;
    postgres=# \q
    

    The first line is in your terminal, the next two are inside psql. Then do your rake db:create.

    The User user is possibly a default but user is already taken for other purposes in PostgreSQL so you'd have to quote it to preserve the case if you wanted to use User as a username:

    postgres=# create role "User" login createdb;
    

    You're better off creating one user per-application anyway.

    You'll want to do similar things for your test entry in database.yml as well.

提交回复
热议问题