Ruby on Rails: Switch From sqlite3 to Postgres

Brenden Thornton
Geek Culture

--

Have you built a Rails application on top of the default sqlite3 database and now want to deploy it to Heroku? Well, I hate to break it to you, but Heroku is not going to be happy about it. That’s probably why you’re reading this article in the first place.

As a fellow junior developer, I also had to go through the process of migrating my database to Postgres for deployment to Heroku and I gotta say, it was rough. That’s why I’ve decided to write a simple article breaking down the process for beginners.

Install Postgres

Before we get started, I would suggest downloading the Postgres.app which provides you a really nice interface for managing your active postgres databases. The specific app I’m suggesting is for Mac OS, but if you are using a different operating system then download the best one for you.

Update Gemfile

The Gemfile is a vital part of any Rails application that maintains all the dependencies for your app. To start the switch over to postgres you’ll need to remove the sqlite gem and install the postgres gem.

Remove sqlite3:

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

And add postgres:

# Use Postgres as the…

--

--

Brenden Thornton
Geek Culture

Full-Stack Developer. @FlatironSchool. UCF. Loving Father & Husband.