将`gem'pg'添加到您的Gemfile中,并确保其版本达到ActiveRecord所需的最低要求

时间:2018-02-21 17:20:04

标签: ruby postgresql heroku rubygems rake

我正在尝试在heroku中安装ruby脚本。当我尝试将其部署到heroku时,我运行bundle installrake db:createrake db:migrate会导致错误,

以下是错误:

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

” 在localhost中,它运行顺畅..

2 个答案:

答案 0 :(得分:3)

使用

创建rails 5应用程序时
rails new app-name -d postgresql

默认情况下,它会将postgres gem(pg)设置为0.21。

当您启动项目时,您可能已跳过此步骤,并在后续阶段添加了pg。让我们回顾一下。

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

然后我编辑了我的Gemfile替换

gem 'sqlite3'

gem 'pg'

然后

bundle install

现在,postgres gem版本是1.0.0。编辑了我的database.yml连接凭据。然后生成模型,迁移,控制器等的一些东西并将它们推送到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

虽然我不喜欢这个版本的pg,但它能正常工作。

然后再次编辑Gemfile,替换,

gem 'pg' 

gem 'pg', '~> 0.18'

然后

$ 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

它仍能正常运作 - https://without-db-sample.herokuapp.com/books

答案 1 :(得分:0)

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

这似乎是一个铁路问题。我会尝试使用gem "pg", "0.21.1"

在gem文件中指定pg gem版本