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

I am new to Rails. This application works fine on my local machine and deploys without any problems. 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. 
+9
ruby-on-rails-4 heroku
source share
4 answers

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

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

It’s clear from the error itself that gem pg must be added to your Gemfile . You may have added it simply, but you need to add a gem to your development and production machine specifically because the Heroku application is the production machine for your system, and your localhost is Development.

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 
+9
source share

just adding gem 'pg' to the gemfile didn't work for me.

It worked for me

gem 'pg', '~> 0.20'

Got this answer from

Heroku and Rails: error loading Gem using Postgres, however it is reported in GEMFILE

Thanks Piers C

And yes, the gem 'rails_12factor' helps when it looks through Heroku logs for error messages.

+37
source share

I got an error while updating gitlab. I ran the wrong command saying that sudo -u git -H bundle install --without postgres development test --deployment instead of the sudo -u git -H bundle install --without mysql development test --deployment package

Just doing

sudo -u git -H bundle install --with postgres did this for me, in your case, probably

bundle install --with postgres and then heroku run rake db:migrate db, heroku run rake db:migrate

0
source share

You can also fix this by upgrading the rails to version> = 5.1.5.

Link: https://github.com/rails/rails/issues/31673

0
source share

All Articles