Mike Rogers βοΈ
Posted on January 31, 2021
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:
https://devcenter.heroku.com/articles/sqlite3
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
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.
Posted on January 31, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.