heroku运行rake db:migrate失败,找不到gem pg;宝石安装pg重复

时间:2015-02-22 10:35:31

标签: ruby-on-rails ruby postgresql heroku gem

我是rails的初学者,试图将我的小应用程序推送到heroku。我在本地将数据库从mysql2移至postgresql,但无法在heroku上运行我的应用。本地一切都按预期运行。

production:
  adapter: postgresql
  database: database_production
  pool: 5
  timeout: 5000

运行heroku run rake db:createheroku run rake db:migrate会返回:

$ heroku run rake --trace db:create
Running `rake --trace db:create` attached to terminal... up, run.5709
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
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).

我可以多次heroku run gem install pg

$ heroku run gem install pg
Running `gem install pg` attached to terminal... up, run.9322
Fetching: pg-0.18.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Installing ri documentation for pg-0.18.1
Done installing documentation for pg after 3 seconds
1 gem installed
$ heroku run gem install pg
Running `gem install pg` attached to terminal... up, run.7925
Fetching: pg-0.18.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Installing ri documentation for pg-0.18.1
Done installing documentation for pg after 4 seconds
1 gem installed
...
..etc

我也注意到一些奇怪的东西,但不确定是否相关。运行heroku run bundle install --no-deployment显示正在安装mysql2,但我已将其从gemfile中删除。

Running `bundle install --no-deployment` attached to terminal... up, run.1928
Fetching gem metadata from https://rubygems.org/.........
Installing i18n 0.7.0
Installing rake 10.4.2
Installing thread_safe 0.3.4
Installing minitest 5.5.1
Installing erubis 2.7.0
Installing builder 3.2.2
Installing mini_portile 0.6.2
Installing rack 1.6.0
Installing mime-types 2.4.3
Installing arel 6.0.0
Installing execjs 2.3.0
Installing sass 3.4.12
Installing json 1.8.2
Installing cancancan 1.10.1
Installing chunky_png 1.3.4
Installing coffee-script-source 1.9.1
Installing thor 0.19.1
Installing multi_json 1.10.1
Installing rb-fsevent 0.9.4
Installing hike 1.2.3
Installing tilt 1.4.1
Installing bcrypt 3.1.10
Using bundler 1.7.12
Installing tzinfo 1.2.2
Installing mysql2 0.3.18
Installing rack-test 0.6.3
Installing mail 2.6.3
Installing compass-import-once 1.0.5
Installing autoprefixer-rails 5.1.7
Installing rdoc 4.2.0
Installing uglifier 2.7.0
Installing coffee-script 2.3.0
Installing compass-core 1.0.3
Installing sprockets 2.12.3
Installing activesupport 4.2.0
Installing bootstrap-sass 3.3.3
Installing sdoc 0.4.1
Installing rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.3
Installing activemodel 4.2.0
Installing jbuilder 2.2.7
Installing activejob 4.2.0
Installing activerecord 4.2.0
Installing ffi 1.9.6
Installing rb-inotify 0.9.5
Installing compass 1.0.3
Installing compass-normalize 1.5
Installing nokogiri 1.6.6.2
Installing loofah 2.0.1
Installing rails-dom-testing 1.0.5
Installing rails-html-sanitizer 1.0.1
Installing actionview 4.2.0
Installing actionpack 4.2.0
Installing sprockets-rails 2.2.4
Installing railties 4.2.0
Installing coffee-rails 4.1.0
Installing sass-rails 5.0.1
Installing turbolinks 2.5.3
Installing jquery-rails 4.0.3
Installing compass-rails 2.0.4
Installing actionmailer 4.2.0
Installing rails 4.2.0
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into ./vendor/bundle

2 个答案:

答案 0 :(得分:1)

您必须将pg添加到Gemfile并运行bundle install,而不是尝试在heroku上手动安装该gem。将其添加到您的应用程序的Gemfile

gem 'pg'

答案 1 :(得分:1)

嘿,伙计们,我弄清楚了我的错误。我的gitbucket repo没有使用最新的gemfile.lock正确更新,所以当我git push heroku master使用了错误的文件进行安装时 - 因此它没有安装gem 'pg'。以下是更新仓库后 remote: Installing pg 0.18.1

<强>结果:

$ git push heroku master
Counting objects: 227, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (188/188), done.
Writing objects: 100% (196/196), 86.44 KiB | 0 bytes/s, done.
Total 196 (delta 116), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.1.5
remote: -----> Installing dependencies using 1.7.12
remote:        Ruby version change detected. Clearing bundler cache.
remote:        Old: ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-linux]
remote:        New: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Installing rake 10.4.2
remote:        Installing i18n 0.7.0
remote:        Installing minitest 5.5.1
remote:        Installing builder 3.2.2
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile 0.6.2
remote:        Installing rack 1.6.0
remote:        Installing json 1.8.2
remote:        Installing mime-types 2.4.3
remote:        Installing arel 6.0.0
remote:        Installing execjs 2.3.0
remote:        Installing sass 3.4.12
remote:        Installing cancancan 1.10.1
remote:        Installing chunky_png 1.3.4
remote:        Installing thread_safe 0.3.4
remote:        Installing coffee-script-source 1.9.1
remote:        Installing bcrypt 3.1.10
remote:        Installing multi_json 1.10.1
remote:        Installing thor 0.19.1
remote:        Installing rb-fsevent 0.9.4
remote:        Installing tilt 1.4.1
remote:        Installing hike 1.2.3
remote:        Installing jquery 0.0.1
remote:        Using bundler 1.7.12
remote:        Installing rails_serve_static_assets 0.0.4
remote:        Installing rails_stdout_logging 0.0.3
remote:        Installing pg 0.18.1
remote:        Installing rack-test 0.6.3
remote:        Installing nokogiri 1.6.6.2
remote:        Installing rdoc 4.2.0
remote:        Installing mail 2.6.3
remote:        Installing autoprefixer-rails 5.1.7
remote:        Installing puma 2.11.1
remote:        Installing uglifier 2.7.0
remote:        Installing compass-import-once 1.0.5
remote:        Installing coffee-script 2.3.0
remote:        Installing tzinfo 1.2.2
remote:        Installing sprockets 2.12.3
remote:        Installing compass-core 1.0.3
remote:        Installing rails_12factor 0.0.2
remote:        Installing loofah 2.0.1
remote:        Installing sdoc 0.4.1
remote:        Installing bootstrap-sass 3.3.3
remote:        Installing activesupport 4.2.0
remote:        Installing rails-html-sanitizer 1.0.1
remote:        Installing rails-deprecated_sanitizer 1.0.3
remote:        Installing globalid 0.3.3
remote:        Installing activemodel 4.2.0
remote:        Installing rails-dom-testing 1.0.5
remote:        Installing jbuilder 2.2.8
remote:        Installing activejob 4.2.0
remote:        Installing activerecord 4.2.0
remote:        Installing actionview 4.2.0
remote:        Installing actionpack 4.2.0
remote:        Installing railties 4.2.0
remote:        Installing actionmailer 4.2.0
remote:        Installing sprockets-rails 2.2.4
remote:        Installing coffee-rails 4.1.0
remote:        Installing sass-rails 5.0.1
remote:        Installing jquery-rails 4.0.3
remote:        Installing rails 4.2.0
remote:        Installing turbolinks 2.5.3
remote:        Installing ffi 1.9.6
remote:        Installing rb-inotify 0.9.5
remote:        Installing compass 1.0.3
remote:        Installing compass-normalize 1.5
remote:        Installing compass-rails 2.0.4
remote:        Your bundle is complete!
remote:        Gems in the groups development and test were not installed.
remote:        It was installed into ./vendor/bundle
remote:        Post-install message from rdoc:
remote:        Depending on your version of ruby, you may need to install ruby rdoc/ri data:
remote:        <= 1.8.6 : unsupported
remote:        = 1.8.7 : gem install rdoc-data; rdoc-data --install
remote:        = 1.9.1 : gem install rdoc-data; rdoc-data --install
remote:        >= 1.9.2 : nothing to do! Yay!
remote:        Post-install message from compass:
remote:        Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks!
remote:        Bundle completed (53.27s)
remote:        Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2015-02-22T12:12:37.186296 #3823]  INFO -- : Writing /tmp/build_39c4ef560255ffc2b75041a3c43b0fe0/public/assets/application-3fbdcccb5f04a215dfa1c3b6cc3d3df5.js
remote:        I, [2015-02-22T12:12:47.594119 #3823]  INFO -- : Writing /tmp/build_39c4ef560255ffc2b75041a3c43b0fe0/public/assets/application-1aa5e71d1c1c4ad6b0fd474b04a30100.css
remote:        Asset precompilation completed (18.56s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote: 
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server (webrick)
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote:        Default types for Ruby  -> console, rake, web, worker
remote: 
remote: -----> Compressing... done, 37.6MB
remote: -----> Launching... done, v7
remote:        https://<app-name>.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy.... done.

感谢所有帮助,我的愚蠢错误。