Bhushan Gohel
Bhushan Gohel

Reputation: 432

"postgresql gem is not loaded" error deploying a Ruby on Rails application on Heroku

I am trying to use postgresql with Ruby on Rails on Heroku but got an error

Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

Please help me to solve this issue.

Upvotes: 14

Views: 17208

Answers (4)

Ramin Mammadzada
Ramin Mammadzada

Reputation: 367

I added the following version into my gemfile, and it is solved.

gem "pg", "~> 0.18"

Upvotes: 0

user2576537
user2576537

Reputation: 801

This worked for me

gem 'pg', '~> 0.20'

Thanks to Piers C

Got this answer from

Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE

Upvotes: 25

vidur punj
vidur punj

Reputation: 5861

Add pg in gemfile

 gem 'pg', '~> 0.20'

then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.

Upvotes: 7

Akshay Borade
Akshay Borade

Reputation: 2472

In your Gemfile

group :production do
  gem 'pg'
end

Then run bundle install and try to deploy on Heroku.

If you want to use PostgreSQL on all environments and not only in production (recommended) add the gem outside the :production group and remove other database adapters such as sqlite.

As a side note, you may also want to add the rails_12factor gem as suggested by Heroku.

Upvotes: 7

Related Questions