Search code examples
herokuruby-on-rails-4

Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile


I'm new to Rails. This application works fine on my local machine, and deploys without any problem. But when I run heroku run rake db:migrate, I get this error:

Running `rake db:migrate` attached to terminal... up, run.1269
rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.

Solution

  • Add this line to your Gemfile inside the :production group (add one if you don't have it).

    group :production do
      gem 'pg'
      gem 'rails_12factor'
    end
    

    It's very clear from the error its self that gem pg needs to be added to your Gemfile. You might be using sqlite3 in your development but Heroku uses postgresql for their database.

    Your Gemfile should look like this:

    source 'https://rubygems.org'
    ruby '2.0.0'
    
    
    gem 'rails', '4.0.0'
    gem 'bootstrap-sass', '2.3.2.0'
    gem 'bcrypt-ruby', '3.0.0'
    gem 'faker', '1.1.2'
    gem 'will_paginate', '3.0.4'
    gem 'bootstrap-will_paginate', '0.0.9'
    
    group :development, :test do
      gem 'sqlite3', '1.3.8'
      gem 'rspec-rails', '2.13.1'
      
    end
    group :doc do
      gem 'sdoc', '0.3.20', require: false
    end
    
    group :production do
      gem 'pg', '0.15.1'
      gem 'rails_12factor'
    end