0
在我的Rails 4應用程序中,我在開發和測試中使用默認的Sqlite3,而在生產中使用Postgresql(Heroku)。Rails 4:從sqlite3遷移後在開發環境中設置Postgresql
我剛剛從Sqlite3切換到Postgresql的所有三個環境,一切工作正常。
我目前的database.yml看起來像這樣:
default: &default
adapter: postgresql
encoding: unicode
username: XXX
password: <--- empty --->
database: name-of-my-app
pool: 5
development:
<<: *default
host: localhost
# 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
host: localhost
production:
<<: *default
host: localhost
正如你所看到的,我使用的是默認的用戶名(我的Mac OSX用戶名)和密碼(沒有密碼)和它們在硬編碼database.yml文件。
如果我理解正確,從我在這裏和那裏閱讀,這是一個雙不好的做法,我應該改爲:
定義自定義的用戶名和密碼
與環境,這樣做變量
這是正確的,那麼正確的做法是什麼?
真棒,非常感謝你爲這個詳細而明確的答案。真的很有幫助。我將根據您的建議更新我的database.yml文件。再次感謝。 –