Heroku和Rails:使用Postgres的Gem加载错误,但是它在GEMFILE中指定 [英] Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE

查看:141
本文介绍了Heroku和Rails:使用Postgres的Gem加载错误,但是它在GEMFILE中指定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图部署一个小项目到Heroku,但是当我部署它并试图运行 heroku运行rake db:migrate 时,它返回了以下错误:

  rake中止! 
Gem :: LoadError:为数据库适配器指定'postgresql',但未加载该gem。将`gem'pg'`添加到您的Gemfile中(并确保其版本处于ActiveRecord所要求的最低限度)。
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in`rescue in spec'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / activerecord-4.2.6 / lib / active_record / connection_adapters / connection_specification.rb:174:在`spec'中
/app/vendor/bundle/ruby/2.2.0 /gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in` establish_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/ active_record / railtie.rb:120:在< class:Railtie>'块(2级)中'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/ active_support / lazy_load_hooks.rb:38:in`instance_eval'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in`execute_hook '
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:28:in'block in on_load'
/ app / vendor /bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/acti ve_support / lazy_load_hooks.rb:27:在`each'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in`on_load '
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in`block in< class:Railtie>'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in`instance_exec'
/app/vendor/bundle/ruby/2.2 .0 / gems / railties-4.2.6 / lib / rails / initializable.rb:30:在`run'中
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/ lib / rails / initializable.rb:55:在`run_initializers'块中
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:54 :在`run_initializers'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:352:in`initialize!'
/ app / config / environment.rb:5:在< top(required)>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/ dependencies.rb:274:在'require'中
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in`block in require'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / activesupport-4.2.6 / lib / active_support / dependencies.rb:240:在`load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport -4.2.6 / lib / active_support / dependencies.rb:274:在'require'中
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application。 rb:328:在`require_environment!'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:457:in`block in run_tasks_blocks'
Gem :: LoadError:pg不是捆绑包的一部分。将它添加到Gemfile。
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:304:in`block in replace_gem'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / activerecord-4.2.6 / lib / active_record / connection_adapters / postgresql_adapter.rb:16:在'< top(required)>'
/ app / vendor / ruby / 2.2.0 / gems / activesupport-4.2.6 / lib / active_support / dependencies.rb:274:在'require'中
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2 .6 / lib / active_support / dependencies.rb:274:在`block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies中。 rb:240:在`load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in`require'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:175:in`spec'
/ app / vendor / bundle / ruby /2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in`esta blish_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:in`block< class(2 levels)in< class:Railtie> ;'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in`instance_eval'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / activesupport-4.2.6 / lib / active_support / lazy_load_hooks.rb:38:在`execute_hook'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport -4.2.6 / lib / active_support / lazy_load_hooks.rb:28:在`block in onload'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/ lazy_load_hooks.rb:27:在`each'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in`on_load'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in`block in< class:Railtie>'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / railties-4.2.6 / lib / rails / initializable.rb:30:在`instance_exec'
/ app / vendor / bundle / ruby​​ / 2.2.0 / gems / railties-4.2.6 / lib / rails / initializable.rb:30:在`run'中
/app/vendor/bundle/ruby/2.2.0 /gems/railties-4.2.6/lib/rails/initializable.rb:55:in`run_initializers中的块'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/ lib / rails / initializable.rb:54:在`run_initializers'中
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
/app/config/environment.rb:5:in`< top(required)>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport -4.2.6 / lib / active_support / dependencies.rb:274:在'require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies中。 rb:274:在`block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in`load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in`require'
/ app / vendor / bundle / ruby /2.2.0/gems/rai lties-4.2.6 / lib / rails / application.rb:328:在`require_environment!'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/ application.rb:457:在`block in run_tasks_blocks'
Tasks:TOP => db:migrate =>环境
(通过使用--trace运行任务查看完整跟踪)

我可以看到我需要在我的gem文件中加载 pg gem的第一行,但是我已经将它加载到生产组中并通过 bundle 。这是我的 GEMFILE

  source'https:// ruby​​gems。 org'
#Bundle edge Rails改为:gem'rails',github:'rails / rails'
gem'rails','4.2.6'
gem'sass-rails',' 〜> 5.0'
gem'uglifier','> = 1.3.0'
gem'coffee-rails','〜> 4.1.0'
gem'jquery-rails'
gem'turbolinks'
gem'jbuilder','〜> 2.0'
gem'sdoc','〜> 0.4.0',group::doc
gem'devise','〜> 3.5','> = 3.5.6'
gem'paperclip','〜> 4.3','> = 4.3.6'
gem'materialize-sass'
gemfont-awesome-rails
gem'bootstrap-sass','〜> 3.2.0'
gem'autoprefixer-rails'
gem'ratyrate'

group:development,:test do
gem'byebug'
end

group:development do
gem'web-console','〜> 2.0'
gem'spring'
end

group:development do
gem'sqlite3'
end

group:生产do
gem'pg'
gem'rails_12factor'
end



<在发布这个问题之前,我已经阅读了相同问题的答案(耙关于数据库适配器与database.yml不一致 rake中止!Gem :: LoadError:为数据库适配器指定'postgresql' Gem :: LoadError:为数据库适配器指定'postgresql',但该gem未加载)使用那里的答案,错误仍然发生。



感谢您的帮助:)

解决方案

尝试在生产环境中编写pg,捆绑,使用gemlock,gemfile和推送代码将代码提交给heroku,然后再次尝试


So I am trying to deploy a small project to Heroku, however when I deployed it and tried to run heroku run rake db:migrate it returned me the following error:

rake aborted!
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).
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in `establish_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:328:in `require_environment!'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:457:in `block in run_tasks_blocks'
Gem::LoadError: pg is not part of the bundle. Add it to Gemfile.
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:304:in `block in replace_gem'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:16:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in `establish_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
/app/config/environment.rb:5:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:328:in `require_environment!'
/app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:457:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

I can see from the first line that I need to load the pg gem in my gem file, however I already have it loaded in the production group and installed through bundle. Here is my GEMFILE:

source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise', '~> 3.5', '>= 3.5.6'
gem 'paperclip', '~> 4.3', '>= 4.3.6'
gem 'materialize-sass'
gem "font-awesome-rails"
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
gem 'ratyrate'

group :development, :test do
    gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

Before posting this question I have read the answers to the same question (rake about database adapter inconsistent with database.yml, rake aborted! Gem::LoadError: Specified 'postgresql' for database adapter, Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded) using the answers there, the error still occurred.

Thanks for helping :)

解决方案

Try to write pg outside production, bundle, commit ur code with gemlock,gemfile and push code to heroku then try again

这篇关于Heroku和Rails:使用Postgres的Gem加载错误,但是它在GEMFILE中指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆