14

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.

4
  • Please add your Gemfile and database.yml files. Commented Aug 1, 2015 at 8:18
  • 2
    Heroku supports only postgresql FYI. Commented Aug 1, 2015 at 8:21
  • add pg gem and run bundle install ...then setup database using heroku run rake db:migrate Commented Aug 1, 2015 at 9:23
  • 1
    What were the reasons for Heroku choosing PostgreSQL over MySQL? Please refer this link quora.com/… Commented Aug 3, 2015 at 13:31

4 Answers 4

25

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

Sign up to request clarification or add additional context in comments.

2 Comments

simply adding gem 'pg' to the gemfile didn't work for me. Seems to be a version issue.
Thank you so much, also commit gemfile.lock, after doing bundle update
7

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.

Comments

7

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.

Comments

0

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

gem "pg", "~> 0.18"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.