Ruby on Rails:我如何编辑postgresql的database.yml?
rails新应用程序=>
当前的database.yml就像那样=>
# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # 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: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000
我需要编辑这个postgresql数据库。
我怎样才能做到这一点 ?
只是:
development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password: host: localhost
来源: configurationRails应用程序
development: adapter: postgresql encoding: utf8 database: name username: hading password: my_db_password pool: 5 # not mandatory timeout: 5000 # not mandatory host: localhost port: your postgresql port number (5432 or 5433)
正如Zabba所说的那样
development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password:
如configurationRails应用程序中所述 。 但是你可能需要额外的min_messages: WARNING
,为了摆脱postgresql在迁移过程中给你的讨厌的NOTICE消息 。 所以我的database.yml
条目看起来像这样
development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password: min_messages: WARNING
您可能有兴趣使用postgres默认值生成新的应用程序:
rails new myapp --database=postgresql
如下所述: https : //devcenter.heroku.com/articles/getting-started-with-rails4
development: adapter: postgresql encoding: utf8 database: name username: hading password: my_db_password host: localhost # not mandatory pool: 5 # not mandatory timeout: 5000 # not mandatory
简单的使用
rails new app_name --database=postgresql
或者现有的应用程序尝试
development: adapter: postgresql encoding: unicode database: app_dev pool: 5 username: username password: password host: localhost