轨道:将Ruby从2.2升级到2.3.3后未加载gem pg

时间:2018-12-01 07:13:28

标签: ruby-on-rails pg

我刚刚将Postgres 9.5的Rails 4.2.0应用程序的ruby从2.2.4升级到了2.3.3。启动rails s时,未加载pg适配器:

C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for data
base 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)

我做了gem install pg来安装pg适配器,并且gem list表示已经安装了pg 1.1.3适配器。但是,启动Rails服务器时仍找不到pg适配器。

Rails 4.2.0的适配器版本是否太新?

gemfile:

source 'http://rubygems.org'

gem 'rails', '4.2.0'

gem 'pg'

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
.........

宝石列表输出:

*** LOCAL GEMS ***

actionmailer (4.2.0)
actionpack (4.2.0)
actionview (4.2.0)
activejob (4.2.0)
activemodel (4.2.0)
activerecord (4.2.0)
activesupport (4.2.0)
addressable (2.5.2)
arel (6.0.4)
bcrypt (3.1.12 x64-mingw32)
bigdecimal (1.2.8)
binding_of_caller (0.8.0)
builder (3.2.3)
bundler (1.17.1)
byebug (10.0.2)
capybara (3.12.0)
coffee-rails (4.1.1)
coffee-script (2.4.1)
coffee-script-source (1.8.0)
concurrent-ruby (1.1.3)
crass (1.0.4)
database_cleaner (1.7.0)
debug_inspector (0.0.3)
did_you_mean (1.0.0)
diff-lcs (1.3)
erubis (2.7.0)
execjs (2.7.0)
factory_girl (4.9.0)
factory_girl_rails (4.9.0)
ffi (1.9.25 x64-mingw32)
globalid (0.4.1)
gon (6.2.1)
hike (1.2.3)
i18n (0.9.5)
io-console (0.4.5)
jquery-rails (4.3.3)
jquery-ui-rails (6.0.1)
json (2.1.0, 1.8.6, 1.8.3)
launchy (2.4.3)
loofah (2.2.3)
mail (2.7.1)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3, 5.8.5)
multi_json (1.13.1)
net-telnet (0.1.1)
nokogiri (1.8.5 x64-mingw32)
pg (1.1.3 x64-mingw32)
power_assert (0.2.6)
protected_attributes (1.1.4)
psych (2.1.0)
public_suffix (3.0.3)
rack (1.6.11)
rack-test (0.6.3)
rails (4.2.0)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.9)
rails-html-sanitizer (1.0.4)
railties (4.2.0)
rake (12.3.1, 10.4.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
rdoc (4.3.0, 4.2.1)
regexp_parser (1.3.0)
request_store (1.4.1)
responders (2.4.0)
rspec-core (3.8.0)
rspec-expectations (3.8.2)
rspec-mocks (3.8.0)
rspec-rails (3.8.1)
rspec-support (3.8.0)
sass (3.7.2)
sass-listen (4.0.0)
sass-rails (5.0.7)
sdoc (0.4.2)
simple_form (3.1.1)
sprockets (2.12.3)
sprockets-rails (2.3.3)
sqlite3 (1.3.13 x64-mingw32)
test-unit (3.1.5)
thor (0.20.3)
thread_safe (0.3.6)
tilt (1.4.1)
tzinfo (1.2.5)
tzinfo-data (1.2018.7)
uglifier (2.7.2)
web-console (2.3.0)
will_paginate (3.1.6)
workflow (1.2.0)
xpath (3.2.0)
yajl-ruby (1.4.1)

1 个答案:

答案 0 :(得分:1)

看起来您的rails和pg gem版本不兼容:https://github.com/rails/rails/issues/31673

我看到三个选项:

  • 将pg gem降级到较旧的版本(可能是0.xx)
  • 升级到Rails 5.1.5或更高版本
  • 尝试github问题中描述的hacky解决方法(不推荐)
相关问题