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

Issue #274 duplicate
Jignesh Gohel
created an issue

The error mentioned in the title is what I was getting despite having following available in my Gemfile and it being installed

gem 'pg'

I encountered the error when I tried to run the following generator command

rails generate authenticate:install

after installing the gem https://github.com/tomichj/authenticate as per instructions here

Trying to search for the error I ended up on this SO Post https://stackoverflow.com/a/44034083/936494 and following the instructions there changing to following made it work.

gem 'pg', '~> 0.21'

As noted in the SO Answer Comment

Version 0.21 works for me but not 1.0.0

Stacktrace:

/home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec': 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)
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:185:in `spec'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/connection_handling.rb:58:in `establish_connection'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `each'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activerecord-5.1.4/lib/active_record/base.rb:25:in `<top (required)>'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/authenticate-0.7.2/lib/generators/authenticate/install/install_generator.rb:162:in `users_table_exists?'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/authenticate-0.7.2/lib/generators/authenticate/install/install_generator.rb:46:in `create_authenticate_user_migration'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `block in invoke_all'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `each'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `map'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:133:in `invoke_all'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/group.rb:232:in `dispatch'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/railties-5.1.4/lib/rails/generators.rb:269:in `invoke'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/railties-5.1.4/lib/rails/commands/generate/generate_command.rb:24:in `perform'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
        from /home/jignesh/.rvm/gems/ruby-2.4.2@my_tool-rails-5.1.4/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
        from bin/rails:9:in `require'
        from bin/rails:9:in `<main>'

Comments (2)

  1. Log in to comment