ruby-on-rails - 如何将 Postgres 数据库添加到现有的 Rails 项目

标签 ruby-on-rails database postgresql

我创建了一个没有数据库的新 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/

相关文章:

ruby-on-rails - Font-Awesome 5 PRO in rails 5 app

ruby-on-rails - 延迟作业记录

ruby-on-rails - Rails 3从联接返回所有列

java - 设置 hibernate JPA

string - PostgreSQL 字符串比较

macos - 在 MacOS X 上不匹配 pg_dump

ruby-on-rails - 使用 ActiveRecord :Relation for specific classes, 并非所有跨 ActiveRecord 的关系

python - 如何在 python MySQLDB 中执行 SQL_CALC_FOUND_ROWS

MySQL - 获取没有时区偏移的日期

node.js - 如何定义 Sequelize.STRING 长度?