我创建了一个没有数据库的新 Rails 项目 (rails new myApp -O)。 我现在如何添加 Postgresql 数据库?
最佳答案
将 pg
gem 添加到您的 gemfile。
# Use postgresql as the database for Active Record
gem 'pg'
然后,如果你没有它,你将需要一个 database.yml
文件在你的 config
目录中,所以去那里并在 config 目录中创建一个名为database.yml
应如下所示。
配置/数据库.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?)
关于ruby-on-rails - 如何将 Postgres 数据库添加到现有的 Rails 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48025797/