PG::ConnectionBad FATAL: role “Myname” does not exist

后端 未结 7 1371
旧巷少年郎
旧巷少年郎 2020-12-13 10:03

I am trying to use PostgreSQL so that I can deploy to Heroku. However I cannot run localhost anymore why? I get the following message:

PG::ConnectionBad
FATA         


        
相关标签:
7条回答
  • 2020-12-13 10:11

    @user3408293

    1. After the installation create a user for postgresql

      sudo -u postgres createuser --superuser $USER

      sudo -u postgres createuser pgs_root

    2. Set user password for the postgresql user

      sudo -u postgres psql postgres

      ( For psql prompt) postgres=# \passsword for ex.- postgres=# \passsword pgs_root

    N.B You should also add username and password to different environments in database.yml file.

    You can also refer this link: Rails: Error installing pg gem

    0 讨论(0)
  • 2020-12-13 10:16

    On Windows, I believe it is a little easier.

    Install postgresql and PGAdmin for your system. See this

    Create a user named postgres and give it a password. You will be nicely prompted to do this.

    Then, when you want to create databases, just right click on your connection and choose New Database. The names of these databases should correspond to what is written in your database.yml

    Run rake db:migrate RAILS_ENV=development (development| test| production).

    These steps worked for me.

    0 讨论(0)
  • 2020-12-13 10:21

    What worked for me was: createuser -P -d -e Myname.

    -P  If given, createuser will issue a prompt for the password of the new user.
          This is not necessary if you do not plan on using password authentication.
    -d  The new user will be allowed to create databases.
    -e  Echo the commands that createuser generates and sends to the server.
    

    If you install Postgresql with homebrew on OSX, there is no default postgres user, and you won't be able to use psql directly without setting up a user first.

    0 讨论(0)
  • 2020-12-13 10:21

    Use this command to use your Postgres user:

    sudo su - postgres

    Now use this command to create a user:

    createuser -s -r 'user_name'

    Now logout.

    The error is resolved.

    0 讨论(0)
  • 2020-12-13 10:22

    The error is "role "Myname" does not exist",

    create the user "Myname" for Postgresql

    sudo -u postgres createuser --superuser Myname

    it will solve this issue.

    0 讨论(0)
  • 2020-12-13 10:27

    I had to go into my PG admin dashboard and create a db/user there. Unfrotunately it was in a subdirectory different from what the tutorials online said(probably updated directory destination last update). Fortunately I was able to find it and create the table/user there, update my database.yml file and then my app was able to work!

    0 讨论(0)
提交回复
热议问题