Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails switch database

I've found info explaining how to set up a Rails application from the beginning using a PostgreSQL database. But I have an application already built. Any advice on steps to take to change my existing application to use PostgreSQL rather than SQLite?

like image 443
Kevin Avatar asked Aug 27 '26 08:08

Kevin


2 Answers

If you're using Rails 6+ you can do this:

rails db:system:change --to=postgresql

where postgresql would be the DB you want.

This was enabled by this commit.

like image 78
emi Avatar answered Aug 29 '26 23:08

emi


Install the pg gem in your Gemfile

gem 'pg'

change the database.yml file to use your database ex.

adapter: postgresql
database: db_name
pool:
timeout:
host: localhost
username: username
password: password

db_name, username, and password values are what you have set your postgresql database too

like image 35
Andre Dublin Avatar answered Aug 29 '26 23:08

Andre Dublin



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!