DEV Community

Cover image for Fixing "sqlite3 gem which is not supported on Heroku"
Mike Rogers ✈️
Mike Rogers ✈️

Posted on

Fixing "sqlite3 gem which is not supported on Heroku"

When I first tried to deploy my Ruby on Rails app to Heroku, I ran into a really annoying error which said:

Failed to install gems via Bundler.
Detected sqlite3 gem which is not supported on Heroku:
Enter fullscreen mode Exit fullscreen mode

The solution, was to change my apps database to use Postgres instead of Sqlite3. In rails there in a terminal command you can run which will do this for you:

$ bundle exec rails db:system:change --to=postgresql
Enter fullscreen mode Exit fullscreen mode

But why do I have to do this?!

Heroku uses an Ephemeral filesystem, which means anything you write to disk won't be persisted between instances of you app. This makes a lot of sense for as you start scaling your app up & need multiple machines to handle requests. But as a result, it's best to treat your apps filesystem as if it's read-only.

The issue is Sqlite3 writes your database to disk, on your local dev machine it's probably stored in db/development.sqlite3. If you had to sync that file between multiple servers running your app, it would be really hard!

So instead we use Postgres which lives on another machine in Heroku world & can share easily offer shared access between multiple instances of our app.

Top comments (1)

mikerogers0 profile image
Mike Rogers ✈️

If you're looking to migrate data, pgloader is a pretty good tool for doing that.