2015-11-04 43 views
0

我做这个启动PostgreSQL服务器:当我尝试做耙分贝:迁移,我得到一个错误:的ActiveRecord :: NODatabaseError作用“Ubuntu的”不存在

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的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 
+0

你有你的配置databases.yml中:

sudo su - postgres psql template1 

然后

CREATE ROLE ubuntu superuser createdb login; 

你可以,如果角色存在,或者不使用命令检查? – Guido

+2

检查'database.yml'并更改用户名。如果你想连接用户'ubuntu',那么你必须先在postgres中创建它。检查[创建角色](http://www.postgresql.org/docs/8.3/static/sql-createrole.html)文档。在你创建它之后,请确保你具有正确的权限[改变角色](http://www.postgresql.org/docs/9.0/static/sql-alterrole.html)。 – radubogdan

+0

是的,我连接到服务。然后我做了创建用户ubuntu SUPERUSER。 usernmae“ubuntu”位于我的database.yml文件中。仍然有同样的问题 – coderk

回答

2

您得到的关于role "ubuntu" does not exist的错误是因为您试图用来从应用程序访问您的postgress会话的用户(或role)。

随着你database.yml指定

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

通知的最后一行:username: ubuntu

你可以去这个

的两种方法:

1)删除线(也许它注释掉) - 这将使您的应用程序连接到您的postgress会话使用默认设置的名称(或role,因为你可能想称它)。默认的大多数时间将是您的机器上的postgress或您的用户名。

2)为你的postgress创建角色ubuntu。要做到这一点,你可以check out this answer.

以上两种方法中的任何一种都适合你。

+0

我刚刚将用户名:ubuntu添加到database.yml,认为这将是一个修复。不过,我删除了它,但仍然遇到了NoDatabseError的相同问题。我会尝试你的第二个选项 – coderk

+0

我对我应该做的事感到困惑。接受你的建议,看看我的结果(我编辑了上面的问题),当我尝试创建一个新的角色。 – coderk

+0

当你进入'psql'并列出所有用户'\ du'时,输出是什么? –

0

改为使用postgres,它是Postgre的默认角色。或者试试这个:

\du 
相关问题