Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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.

like image 645
Bhushan Gohel Avatar asked Aug 01 '15 08:08

Bhushan Gohel


3 Answers

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

like image 123
user2576537 Avatar answered Nov 15 '22 08:11

user2576537


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.

like image 7
Akshay Borade Avatar answered Nov 15 '22 08:11

Akshay Borade


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.

like image 7
vidur punj Avatar answered Nov 15 '22 07:11

vidur punj