【发布时间】:2012-12-24 18:09:14
【问题描述】:
我使用默认的 SQLite 数据库生成了我的 rails 应用程序,但是在创建了几个模型并迁移了几次之后,我想将其更改为 Postgresql。
我将 postgres gem 添加到我的 Gemfile,捆绑安装,然后我替换了我的所有 database.yml 代码
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
到
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: mypass
development:
<<: *default
database: sample_app_development
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_production
即使密码正确,我也会收到 FATAL: password authentication failed for user "postgres" 错误。是因为我错过了一步吗?我是否应该使用 pg Admin III 告诉 PG 我想将此应用程序添加到我的服务器?我应该创建一个新角色/连接吗?
我遇到过几次这个问题,但似乎无法找到这个特定问题的答案。
当我尝试运行 rake db:drop 时它给了我这个:
Couldn't drop sample_app_development : #<PGError: FATAL: role "postgres" does not exist
>
Couldn't drop sample_app_test : #<PGError: FATAL: role "postgres" does not exist
>
=========
Edmunds-MacBook-Pro:sample_app edmundmai$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
Password:
createuser: could not connect to database postgres: FATAL: password authentication failed for user "edmundmai"
【问题讨论】:
-
我认为你至少需要设置
host和port参数;见stackoverflow.com/questions/10263821/… -
添加后我仍然收到角色不存在的错误。究竟什么是角色,如何创建新角色?
-
@Edmund - 对于简单版本,只需将角色视为用户。如果你真的想深入了解,the docs 有一个更长的讨论。