【发布时间】:2016-02-05 10:41:12
【问题描述】:
我通过这样做启动了 postgresql 服务器:
sudo service postgresql start
然后我连接到服务:
sudo sudo -u postgres psql
然后我创建了一个数据库(我正在尝试将投票系统添加到我的应用程序):
postgres=# CREATE DATABASE "votes";
但我仍然有同样的问题。
还有,当我这样做时
rake db:create
我得到一个角色“ubuntu”不存在错误
这是我的 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
我正在尝试创建一个 ubuntu 角色:
$ 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
【问题讨论】:
-
你配置你的databases.yml了吗?
-
检查
database.yml并更改用户名。如果您想与用户ubuntu连接,那么您必须先在 postgres 中创建它。检查create role 文档。创建它后,请确保您 alter role 具有正确的权限。 -
是的,我已连接到该服务。然后我创建了用户 ubuntu SUPERUSER。用户名“ubuntu”在我的 database.yml 文件中。仍然遇到同样的问题
-
在 Postgres 中,用户和角色是不等价的。如果
CREATE USER不够用,您应该重新阅读@radubogdan 的评论并查看CREATE ROLE和ALTER ROLE。
标签: ruby-on-rails ruby postgresql activerecord