如何将Postgre数据库添加到现有的Rails项目中

问题描述 投票:1回答:1

我创建了一个没有数据库的新Rails项目(rails new myApp -O)。我现在如何添加Postgresql数据库?

ruby-on-rails database postgresql
1个回答
1
投票

pg gem添加到您的gemfile中。

# Use postgresql as the database for Active Record
gem 'pg'

然后,如果你没有它,你需要在database.yml目录中有一个config文件,所以去那里并在config目录中创建一个名为database.yml的fole,它应该是这样的。

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?)
© www.soinside.com 2019 - 2024. All rights reserved.