More On PostgreSQL and Rails

I had already posted on getting a Rails app to work with PostgreSQL. For that app, I was starting over from SQLite.

But now I am starting to use PostgreSQL from the beginning since Heroku runs on PostgreSQL. I learned more about this from RailsCasts.

First you have to use the –database option when you make the app:

rails new some_app --database=postgresql

Then you need to edit the config/database.yml file. I have not sent my app to Heroku yet, so I comment out the prod stanza. For the test and development stanzas I change the username to the username that I am logged in as on my Ubuntu laptop.

Then I run

rake db:create:all

Then you can run

rake db:migrate

Don’t forget to run this after each migration as well:

rake db:test:prepare



There are 141 words in this article.