Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add `gem 'pg'` to your Gemfile and ensure its version is at the minimum required by ActiveRecord

I am trying to install a ruby script in heroku. I run bundle install, rake db:create, rake db:migrate when I tried to deploy it to heroku it throws an error,

Here is the Error :

Counting objects: 858, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (366/366), done.
Writing objects: 100% (858/858), 1.27 MiB | 158.00 KiB/s, done.
Total 858 (delta 434), reused 858 (delta 434)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: ###### WARNING:
remote:        Removing `Gemfile.lock` because it was generated on Windows.
remote:        Bundler will do a full resolve so native gems are handled properly.
remote:        This may result in unexpected gem versions being used in your app.
remote:        In rare occasions Bundler may not be able to resolve your dependencies at all.
remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote: 
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
remote:        The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
remote:        Fetching gem metadata from https://rubygems.org/..........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Resolving dependencies...
remote:        Fetching rake 12.3.0
remote:        Fetching concurrent-ruby 1.0.5
remote:        Fetching minitest 5.11.3
remote:        Installing rake 12.3.0
remote:        Installing minitest 5.11.3
remote:        Installing concurrent-ruby 1.0.5
remote:        Fetching thread_safe 0.3.6
remote:        Fetching builder 3.2.3
remote:        Installing thread_safe 0.3.6
remote:        Installing builder 3.2.3
remote:        Fetching erubis 2.7.0
remote:        Fetching mini_portile2 2.3.0
remote:        Fetching crass 1.0.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.3.0
remote:        Installing crass 1.0.3
remote:        Fetching rack 2.0.4
remote:        Fetching nio4r 2.2.0
remote:        Installing rack 2.0.4
remote:        Installing nio4r 2.2.0 with native extensions
remote:        Fetching websocket-extensions 0.1.3
remote:        Fetching mini_mime 1.0.0
remote:        Installing websocket-extensions 0.1.3
remote:        Fetching coffee-script-source 1.12.2
remote:        Installing mini_mime 1.0.0
remote:        Installing coffee-script-source 1.12.2
remote:        Fetching execjs 2.7.0
remote:        Installing execjs 2.7.0
remote:        Fetching method_source 0.9.0
remote:        Fetching thor 0.20.0
remote:        Installing thor 0.20.0
remote:        Installing method_source 0.9.0
remote:        Fetching formtastic_i18n 0.6.0
remote:        Installing formtastic_i18n 0.6.0
remote:        Fetching kaminari-core 1.1.1
remote:        Fetching arel 7.1.4
remote:        Installing kaminari-core 1.1.1
remote:        Installing arel 7.1.4
remote:        Fetching rb-fsevent 0.10.2
remote:        Fetching ffi 1.9.21
remote:        Installing rb-fsevent 0.10.2
remote:        Fetching bcrypt 3.1.11
remote:        Installing bcrypt 3.1.11 with native extensions
remote:        Installing ffi 1.9.21 with native extensions
remote:        Using bundler 1.15.2
remote:        Fetching orm_adapter 0.5.0
remote:        Installing orm_adapter 0.5.0
remote:        Fetching multi_json 1.13.1
remote:        Installing multi_json 1.13.1
remote:        Fetching nested_scaffold 1.0.0
remote:        Installing nested_scaffold 1.0.0
remote:        Fetching pg 1.0.0
remote:        Installing pg 1.0.0 with native extensions
remote:        Fetching puma 3.11.2
remote:        Installing puma 3.11.2 with native extensions
remote:        Fetching tilt 2.0.8
remote:        Installing tilt 2.0.8
remote:        Fetching turbolinks-source 5.1.0
remote:        Installing turbolinks-source 5.1.0
remote:        Fetching will_paginate 3.1.6
remote:        Installing will_paginate 3.1.6
remote:        Fetching i18n 0.9.5
remote:        Installing i18n 0.9.5
remote:        Fetching tzinfo 1.2.5
remote:        Installing tzinfo 1.2.5
remote:        Fetching nokogiri 1.8.2
remote:        Installing nokogiri 1.8.2 with native extensions
remote:        Fetching rack-test 0.6.3
remote:        Installing rack-test 0.6.3
remote:        Fetching sprockets 3.7.1
remote:        Installing sprockets 3.7.1
remote:        Fetching warden 1.2.7
remote:        Installing warden 1.2.7
remote:        Fetching websocket-driver 0.6.5
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Fetching mail 2.7.0
remote:        Installing mail 2.7.0
remote:        Fetching coffee-script 2.4.1
remote:        Installing coffee-script 2.4.1
remote:        Fetching autoprefixer-rails 8.0.0
remote:        Installing autoprefixer-rails 8.0.0
remote:        Fetching uglifier 4.1.6
remote:        Installing uglifier 4.1.6
remote:        Fetching rb-inotify 0.9.10
remote:        Installing rb-inotify 0.9.10
remote:        Fetching turbolinks 5.1.0
remote:        Installing turbolinks 5.1.0
remote:        Fetching activesupport 5.0.6
remote:        Installing activesupport 5.0.6
remote:        Fetching sass-listen 4.0.0
remote:        Installing sass-listen 4.0.0
remote:        Fetching globalid 0.4.1
remote:        Installing globalid 0.4.1
remote:        Fetching arbre 1.1.1
remote:        Installing arbre 1.1.1
remote:        Fetching activemodel 5.0.6
remote:        Installing activemodel 5.0.6
remote:        Fetching jbuilder 2.7.0
remote:        Installing jbuilder 2.7.0
remote:        Fetching sass 3.5.5
remote:        Installing sass 3.5.5
remote:        Fetching activejob 5.0.6
remote:        Installing activejob 5.0.6
remote:        Fetching activerecord 5.0.6
remote:        Installing activerecord 5.0.6
remote:        Fetching bootstrap-sass 3.3.7
remote:        Installing bootstrap-sass 3.3.7
remote:        Fetching kaminari-activerecord 1.1.1
remote:        Installing kaminari-activerecord 1.1.1
remote:        Fetching polyamorous 1.3.3
remote:        Installing polyamorous 1.3.3
remote:        Fetching rails-dom-testing 2.0.3
remote:        Fetching loofah 2.2.0
remote:        Installing rails-dom-testing 2.0.3
remote:        Installing loofah 2.2.0
remote:        Fetching rails-html-sanitizer 1.0.3
remote:        Installing rails-html-sanitizer 1.0.3
remote:        Fetching actionview 5.0.6
remote:        Installing actionview 5.0.6
remote:        Fetching kaminari-actionview 1.1.1
remote:        Fetching actionpack 5.0.6
remote:        Installing kaminari-actionview 1.1.1
remote:        Fetching kaminari 1.1.1
remote:        Installing actionpack 5.0.6
remote:        Installing kaminari 1.1.1
remote:        Fetching actioncable 5.0.6
remote:        Fetching actionmailer 5.0.6
remote:        Fetching railties 5.0.6
remote:        Installing actionmailer 5.0.6
remote:        Installing actioncable 5.0.6
remote:        Fetching formtastic 3.1.5
remote:        Installing railties 5.0.6
remote:        Fetching has_scope 0.7.1
remote:        Installing formtastic 3.1.5
remote:        Installing has_scope 0.7.1
remote:        Fetching ransack 1.8.7
remote:        Installing ransack 1.8.7
remote:        Fetching sprockets-rails 3.2.1
remote:        Installing sprockets-rails 3.2.1
remote:        Fetching simple_form 3.5.1
remote:        Installing simple_form 3.5.1
remote:        Fetching coffee-rails 4.2.2
remote:        Fetching responders 2.4.0
remote:        Installing coffee-rails 4.2.2
remote:        Installing responders 2.4.0
remote:        Fetching jquery-rails 4.3.1
remote:        Fetching rails 5.0.6
remote:        Installing rails 5.0.6
remote:        Fetching sass-rails 5.0.7
remote:        Installing sass-rails 5.0.7
remote:        Fetching inherited_resources 1.8.0
remote:        Fetching devise 4.4.1
remote:        Installing inherited_resources 1.8.0
remote:        Installing jquery-rails 4.3.1
remote:        Installing devise 4.4.1
remote:        Fetching activeadmin 1.2.1
remote:        Installing activeadmin 1.2.1
remote:        Bundle complete! 18 Gemfile dependencies, 79 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (30.42s)
remote:        Cleaning up the bundler cache.
remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        DEPRECATION WARNING: `config.static_cache_control` is deprecated and will be removed in Rails 5.1.
remote:        Please use
remote:        `config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=2592000' }`
remote:        instead.
remote:        (called from block in <top (required)> at /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/config/environments/production.rb:28)
remote:        intializing git
remote:        rake aborted!
remote:        Gem::LoadError: 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).
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/connection_specification.rb:176:in `rescue in spec'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/connection_specification.rb:173:in `spec'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_handling.rb:53:in `establish_connection'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/railtie.rb:125:in `block (2 levels) in <class:Railtie>'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:49:in `each'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'

remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/devise-4.4.1/lib/devise/mapping.rb:78:in `modules'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/devise-4.4.1/lib/devise/mapping.rb:95:in `routes'
remote:        
        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/railties-5.0.6/lib/rails/initializable.rb:55:in `block in run_initializers'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/railties-5.0.6/lib/rails/initializable.rb:54:in `run_initializers'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/railties-5.0.6/lib/rails/application.rb:352:in `initialize!'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/config/environment.rb:5:in `<top (required)>'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `block in require'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in `load_dependency'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/railties-5.0.6/lib/rails/application.rb:328:in `require_environment!'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/railties-5.0.6/lib/rails/application.rb:448:in `block in run_tasks_blocks'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
remote:        /tmp/build_95d492fa8732a678c298a47e2e3bb8e4/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to limitless-hamlet-95451.
remote: 
To https://git.heroku.com/limitless-hamlet-95451.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/limitless-hamlet-95451.git

' In localhost it runs smooth..

like image 490
Bsde Avatar asked Feb 21 '18 17:02

Bsde


People also ask

How do you install gems you added to your Gemfile?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.

What is PG gem?

Pg is the Ruby interface to the PostgreSQL RDBMS. It works with PostgreSQL 9.3 and later.

How do I change my Gemfile version?

Process: install the gem generically, looking up your target version on rubygems.org, then update and version your Gemfile. the install command is in the right-hand column. then you can: gem install gem_name -v 1.5.

What is Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.


1 Answers

When you create a rails 5 application with

rails new app-name -d postgresql

it will set postgres gem (pg) to 0.21 by default.

Possibly you've skipped this step when you started your project, and added pg on later stages. Let's rewind.

rails new without-db #defaults to sqlite3
cd  without-db

Then I've edited my Gemfile replacing

gem 'sqlite3'

to

gem 'pg'

then

bundle install

Now, postgres gem version is 1.0.0. Edited my database.yml for connection credentials.Then some stuff to generate model, migration, controller etc. and push them to heroku.

$ rails g scaffold book title:string author:string genre:string description:string
...
$ rake db:create
...
$ rake db:migrate
...
$ heroku login
...
$ git init
...
$ heroku git:remote -a without-db-sample
...
$ git add .
... 
$ git commit -m "initial commit"
...
$ git push heroku master
...
$ heroku run rake db:migrate
...
$ heroku open

Albeit I don't love this version of pg, it worked normally.

Then edited Gemfile again, replacing,

gem 'pg' 

to

gem 'pg', '~> 0.18'

then

$ bundle install
... 
$ bundle show pg
/home/ziya/.rvm/gems/ruby-2.4.1/gems/pg-0.21.0
$ git status
...
$ git add .
...
$ git commit -m "change postgres version"
...
$ git push heroku master

It still works normally - https://without-db-sample.herokuapp.com/books

like image 72
marmeladze Avatar answered Oct 22 '22 22:10

marmeladze