我创建了一个不包含数据库的新Rails项目(rails new myApp -O)。 现在我该如何添加Postgresql数据库?
我创建了一个不包含数据库的新Rails项目(rails new myApp -O)。 现在我该如何添加Postgresql数据库?
pg
宝石添加到您的gemfile中。# Use postgresql as the database for Active Record
gem 'pg'
接下来,如果你没有这个文件,你需要在你的config
目录下创建一个database.yml
文件,因此进入该目录并创建名为database.yml
的文件,其内容应该如下所示。
config/database.yml
default: &default
adapter: postgresql
encoding: unicode
username: your username for your Postgresql access
password: your password for your Postgresql access
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: The name for your **development** database that you created (probably in PGAdmin?)
test:
<<: *default
database: The name for your **test** database that you created (probably in PGAdmin?)
production:
<<: *default
database: The name for your **production** database that you created (probably in PGAdmin?)