when I try to do rake db:migrate, I get an error: ActiveRecord::NODatabaseError role “ubuntu” does not exist

为君一笑 提交于 2019-12-12 04:15:16

问题


I started the postgresql server by doing this:

sudo service postgresql start

then I connected to the service:

sudo sudo -u postgres psql

then I created a database (i'm trying to add a voting system to my app):

postgres=# CREATE DATABASE "votes";

but i still have the same problem.

Also, when I do

rake db:create

I get a role "ubuntu" does not exist error

Here is my database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
# default: &default
#   adapter: sqlite3
#   pool: 5
#   timeout: 5000

# development:
#   <<: *default
#   database: db/development.sqlite3

# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   <<: *default
#   database: db/test.sqlite3

# production:
#   <<: *default
#   database: db/production.sqlite3

# FOR HEROKU -- POSTGRES DB SETUP
# UNCOMMENT WHEN WORKING LOCALLY.
development:
  adapter: postgresql
  database: votes
  pool: 5
  timeout: 5000
  username: ubuntu

test:
  adapter: postgresql
  database: planit_test
  pool: 5
  timeout: 5000


# production:
#   <<: *default
#   database: db/production.sqlite3

I'm trying to create an ubuntu rold:

$ sudo sudo -u postgres psql
psql (9.3.10)
Type "help" for help.

postgres=# CREATE ROLE ubuntu SUPERUSER
postgres-# \q
$ rake db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "ubuntu" does not exist

回答1:


The error you are getting about role "ubuntu" does not exist is because of the user (or role) that you are trying to use to access your postgress session from the app.

As your database.yml specified

development:
  adapter: postgresql
  database: votes
  pool: 5
  timeout: 5000
  username: ubuntu

Notice the last line: username: ubuntu?

Two ways you can go about this are:

1) Remove that line (maybe comment it out) - This will make your app connect to your postgress session with the default set name (or role, as you may want to call it). The default most times will be postgress or your username on your machine.

2) create the role ubuntu for your postgress. To do this, you can check out this answer.

Either of the above two ways should work well for you.




回答2:


Use postgres instead, it's default role from Postgre. Or try this one:

    sudo su - postgres
    psql template1

then

    CREATE ROLE ubuntu superuser createdb login;

You can check if the role exist or not with command:

    \du


来源:https://stackoverflow.com/questions/33530287/when-i-try-to-do-rake-dbmigrate-i-get-an-error-activerecordnodatabaseerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!