当前位置: 首页 > 知识库问答 >
问题:

当我尝试执行rake db:migrate时,我得到一个错误:ActiveRecord::NodatabaseError角色“Ubuntu”不存在

仇正平
2023-03-14

我通过以下操作启动了postgresql服务器:

sudo service postgresql start

然后我连接到服务:

sudo sudo -u postgres psql
postgres=# CREATE DATABASE "votes";
rake db:create
# 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
$ 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个答案

汪信鸥
2023-03-14

关于角色“Ubuntu”不存在的错误是因为您试图使用用户(或角色)从应用程序访问Postgence会话。

database.yml所指定

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

注意最后一行:username:ubuntu

以上两种方法中的任何一种都应该对你很有效。

 类似资料: