我使用默認的SQLite數據庫生成了我的rails應用程序,但創建了幾個模型並遷移了幾次後,我想將其更改爲Postgresql。Rails:如何在開發過程中將數據庫從SQLite更改爲PG?
我把Postgres寶石我的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使用PG Admin III,我想將這個應用程序添加到我的服務器?我應該創建一個新的角色/連接?
我已經遇到了這個問題幾次,似乎無法找到這個具體問題的答案。
它給了我這個當我嘗試運行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'參數;請參閱http://stackoverflow.com/questions/10263821/rails-rake-dbcreateall-fails-to-connect-to-postgresql-database – Baldrick
添加後,我仍然得到該角色不存在的錯誤。究竟是一個角色,我如何創建新的角色? – Edmund
@Edmund - 對於簡單的版本,只需將角色想象爲一個用戶即可。如果你真的想深入研究,[文檔](http://www.postgresql.org/docs/9.2/static/user-manag.html)有更長的討論。 –