The Problem
When I’m developing a rails website, my database is usually using SQLite3. It is pretty easy to get up and running and usually is enough for developing small scale apps. However, SQLite3 is not really suited for production environments, i.e. if you want this website out in the world wild web, you going to want a production centric database like Postgres or MySQL. For a small fun website on Heroku, you’ll want to convert your app to use Postgres.
I had already connected my app to Heroku, but couldn’t get it to deploy because it wasn’t cool with using SQLite3. Here’s a overview of my journey to get it working.
Installing Postgres
If you are developing on a Mac, you already have SQLite3 installed. If you don’t already have Postgres installed, you’ll want to download and install from the Postgres site if you want to develop with it. The Postgres.app makes installation pretty easy.
Next you’ll want to configure your app to use Postgres instead of SQLite. Find the line in your Gemfile in your site’s root directory and remove it.
Replace it with
Then run bundle install
. Now we can start configuring the database to use Postgres.
Configuring the Database
You will need to convert your config/database.yml. Mine looked like this:
Changed it to
Not having deployed a live site on anything, I was having trouble figuring why Heroku was deploying without errors, but everything was failing to load. I forgot to migrate! Since the site is using Heroku as a platform, I needed to prepend the heroku client commands to the usual rake commands
Visit your site on Heroku and happy developing!