Last Updated: May 15, 2019
· mindeavor

Rails 3 development: Switch from sqlite3 to pg (postgresql)

This is mostly a note to myself, since I keep forgetting.

If you created a standard rails project, but later want to switch to using the pg gem, here's what you need to do:

WARNING: This method does not migrate old data.

In Gemfile:

group :development do
  # gem 'sqlite3'
  gem 'pg'

In database.yml:

  # adapter: sqlite3
  # database: db/development.sqlite3
  host: localhost
  adapter: postgresql
  database: myapp_dev
  username: mydbuser

On the command line:

$ bundle install
$ bundle exec rake db:create db:migrate

2 Responses
Add your response

I tried the following but was receiving a bunch of errors:, any ideas?

over 1 year ago ·

blklane, my guess is that postgres is not running on your machine; you need to start it first.

over 1 year ago ·