我创建了一个没有数据库的新Rails项目(rails new myApp -O)。 我现在如何添加Postgresql数据库?
答案 0 :(得分:1)
将pg
gem添加到您的gemfile中。
# Use postgresql as the database for Active Record
gem 'pg'
然后,如果你没有它,你需要database.yml
目录中的config
文件,所以去那里并在config目录中创建一个名为database.yml
的fole,它应该看起来像像这样。
配置/ 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?)