我使用默认的 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"