Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Postgre Database to an existing Rails project

I created a new Rails project without database (rails new myApp -O). How can I add a Postgresql database now ?

like image 902
romss182 Avatar asked Oct 26 '25 07:10

romss182


1 Answers

Add the pg gem to your gemfile.

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

Then, if you do not have it, you will need a database.yml file in your config directory so go there and in the config directory create a fole called database.yml which should look like this.

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?)
like image 52
Rockwell Rice Avatar answered Oct 28 '25 22:10

Rockwell Rice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!