SQLite3 — PostgreSQL Workaround for Deploying Rails App on Heroku

Kunal Shah
2 min readMay 10, 2021

Congrats on creating your web application and getting ready to deploy it! However, I bet you have come across a similar problem to many others:

Heroku requires you to use Postgres. You can find the reasoning here: https://devcenter.heroku.com/articles/sqlite3.

But you have built your whole app using SQLite. I have been there, and I wanted to relay a quick workaround so that you can get your app up and running on Heroku without needing to install PostgreSQL.

NOTE: this could possibly cause small bugs or performance as apps scale, but I have not encountered any major issues. If you plan to scale the app or use it for anything other than a project showcase, I would recommend completely moving to PostgreSQL.

Changing Your Gemfile

Open your Gemfile and look near the top where you see the gem for SQLite

# Use sqlite3 as the database for Active Record
gem ‘sqlite3’, ‘~> 1.4’

Cut and paste that line of code into the Development/Test Group below

group :development, :test do
# Call ‘byebug’ anywhere in the code to stop execution and get a debugger console
gem ‘byebug’, platforms: [:mri, :mingw, :x64_mingw]
# Use sqlite3 as the database for Active Record
gem ‘sqlite3’, ‘~> 1.4’
end

Then add a new Production Group into the Gemfile with the Postgres gem dependency

group :production do
gem ‘pg’
end

This tells your app when it runs in production to use PostgreSQL and when in development or testing to use SQLite. So when you deploy on Heroku and it runs your app via production, it will recognize the database as PostgreSQL

Finally when need to lock in these changes, so in your terminal run

bundle install

and this will generate a new Gemfile.Lock file.

Now you should be able to deploy your app to Heroku!

Happy Coding!

--

--

Kunal Shah

Full Stack Web Developer | Flatiron School Software Engineering Graduate | TV Show Enthusiast. Pittsburgh Sports Fanatic.