Thursday, 16 February 2012

Switching Rails app from SQLite to Postgres

I decided that my new Rails app was to be hosted with Heroku, but I decided it a little too late, having already built most of it using, by default, SQLite. I tried to wing it and hope that there would be no compatibility problems, but I was getting errors in some db queries on Heroku that I wasn't seeing locally on SQLite.

So, time to switch my app to Postgres. This Youtube video gave me most of what I needed about installing Postgres on my Mac, but because I'm running Lion I then needed to consider this stackoverflow thread too, as only at this point did I learn that postgres is bundled into Lion already.

Once postgres was installed and running I created a database named myRailsApp_development and gave it a user (all shown in the youtube video linked above), and modified the database.yml file in my Rails app thus:

  adapter: postgresql
  encoding: utf8
  database: myRailsApp_development
  pool: 5
  username: myUser
  host: localhost

Then I ran rake db:migrate, and it all worked!

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!