Convert SQLite to Postgre in Rails

Photo by Markus Winkler on Unsplash

So you want to convert your SQLite database in Rails to Postgre? That is why you are here right? Let’s get started. 😊

Check Postgre Version

psql -V

If nothing comes up then you will have to install Postgre.

For New Projects

rails new my_app --database=postgresql

This should take care of all your woes. If it doesn’t then read on.

For Existing Projects

1. gem 'pg' 2. bundle install

You will need to modify your database.yml file to pull from Postgre for all three environments.

development:adapter: postgresqldatabase: my_database_developmentusername: my_usernamepassword: my_passwordpool: 5timeout: 5000
test:adapter: postgresqldatabase: my_database_testusername: my_usernamepassword: my_passwordpool: 5timeout: 5000production:adapter: postgresqldatabase: my_database_productionusername: my_usernamepassword: my_passwordpool: 5timeout: 5000

With Postgre, each environment has its own separate database, username, and password. This was an ah-ha moment for me. It is something you do not think about when you are coming from using SQLite.


Full-Stack Software Engineer and Lifelong Learner