升级 Redmine,activerecord-mysql2-apter 不工作

升级 Redmine,activerecord-mysql2-apter 不工作

为了将 Redmine 从 1.0.1 升级到 2.1.2,我需要执行以下命令: rake db:migrate RAILS_ENV=production

但是,这样做会产生以下错误: rake aborted! Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (mysql2 is not part of the bundle. Add it to Gemfile.)

我已经运行了gem install activerecord-mysql2-adapter,但是当我尝试运行命令时仍然出现相同的错误rake ...

如何让我的 RoR 应用程序识别我已经安装了 mysql2 适配器?或者我的 activerecord-mysql2-adapter 安装有问题吗?


结果sudo bundle install

Using rake (10.0.0) 
Using i18n (0.6.1) 
Using multi_json (1.3.7) 
Using activesupport (3.2.8) 
Using builder (3.0.0) 
Using activemodel (3.2.8) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.8) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.8) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.8) 
Using activeresource (3.2.8) 
Using coderay (1.0.8) 
Using fastercsv (1.5.5) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.8) 
Using jquery-rails (2.0.3) 
Using metaclass (0.0.1) 
Using mocha (0.12.3) 
Using mysql (2.8.1) 
Using net-ldap (0.3.1) 
Using pg (0.14.1) 
Using ruby-openid (2.1.8) 
Using rack-openid (1.3.1) 
Using bundler (1.2.1) 
Using rails (3.2.8) 
Using rmagick (2.13.1) 
Using shoulda (2.11.3) 
Using sqlite3 (1.3.6) 
Using yard (0.8.3) 
[32mYour bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.[0m

结果sudo find / -name "*mysql2*"

/var/lib/gems/1.8/doc/mysql2-0.3.11
/var/lib/gems/1.8/doc/activerecord-3.2.9/ri/ActiveRecord/Base/mysql2_connection-c.ri
/var/lib/gems/1.8/doc/activerecord-mysql2-adapter-0.0.3
/var/lib/gems/1.8/doc/activerecord-mysql2-adapter-0.0.3/ri/ActiveRecord/Base/em_mysql2_connection-c.ri
/var/lib/gems/1.8/doc/activerecord-mysql2-adapter-0.0.3/ri/ActiveRecord/Base/mysql2_connection-c.ri
/var/lib/gems/1.8/gems/mysql2-0.3.11
/var/lib/gems/1.8/gems/mysql2-0.3.11/spec/mysql2
/var/lib/gems/1.8/gems/mysql2-0.3.11/mysql2.gemspec
/var/lib/gems/1.8/gems/mysql2-0.3.11/lib/mysql2.rb
/var/lib/gems/1.8/gems/mysql2-0.3.11/lib/mysql2
/var/lib/gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.so
/var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2
/var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2/mysql2.so
/var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2/mysql2_ext.c
/var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2/mysql2_ext.h
/var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2/mysql2_ext.o
/var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/activerecord-mysql2-adapter.gemspec
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/lib/arel/engines/sql/compilers/mysql2_compiler.rb
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/lib/activerecord-mysql2-adapter.rb
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/lib/activerecord-mysql2-adapter
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/em_mysql2_adapter.rb
/var/lib/gems/1.8/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb
/var/lib/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb
/var/lib/gems/1.8/cache/mysql2-0.3.11.gem
/var/lib/gems/1.8/cache/activerecord-mysql2-adapter-0.0.3.gem
/var/lib/gems/1.8/specifications/activerecord-mysql2-adapter-0.0.3.gemspec
/var/lib/gems/1.8/specifications/mysql2-0.3.11.gemspec

内容/usr/share/redmine/Gemfile

source 'http://rubygems.org'

gem 'rails', '3.2.8'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"

# Optional gem for LDAP authentication
group :ldap do
  gem "net-ldap", "~> 0.3.1"
end

# Optional gem for OpenID authentication
group :openid do
  gem "ruby-openid", "~> 2.1.4", :require => "openid"
  gem "rack-openid"
end

# Optional gem for exporting the gantt to a PNG file, not supported with jruby
platforms :mri, :mingw do
  group :rmagick do
    # RMagick 2 supports ruby 1.9
    # RMagick 1 would be fine for ruby 1.8 but Bundler does not support
    # different requirements for the same gem on different platforms
    gem "rmagick", ">= 2.0.0"
  end
end

# Database gems
platforms :mri, :mingw do
  group :postgresql do
    gem "pg", ">= 0.11.0"
  end

  group :sqlite do
    gem "sqlite3"
  end
end

platforms :mri_18, :mingw_18 do
  group :mysql do
    gem "mysql"
  end
end

platforms :mri_19, :mingw_19 do
  group :mysql do
    gem "mysql2", "~> 0.3.11"
  end
end

platforms :jruby do
  gem "jruby-openssl"

  group :mysql do
    gem "activerecord-jdbcmysql-adapter"
  end

  group :postgresql do
    gem "activerecord-jdbcpostgresql-adapter"
  end

  group :sqlite do
    gem "activerecord-jdbcsqlite3-adapter"
  end
end

group :development do
  gem "rdoc", ">= 2.4.2"
  gem "yard"
end

group :test do
  gem "shoulda", "~> 2.11"
  # Shoulda does not work nice on Ruby 1.9.3 and seems to need test-unit explicitely.
  gem "test-unit", :platforms => [:mri_19]
  gem "mocha", "0.12.3"
end

local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
  puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
  instance_eval File.read(local_gemfile)
end

# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
  puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
  instance_eval File.read(file)
end

内容/usr/share/redmine/Gemfile.lock

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (3.2.8)
      actionpack (= 3.2.8)
      mail (~> 2.4.4)
    actionpack (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.1.3)
    activemodel (3.2.8)
      activesupport (= 3.2.8)
      builder (~> 3.0.0)
    activerecord (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.8)
      activemodel (= 3.2.8)
      activesupport (= 3.2.8)
    activesupport (3.2.8)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.0)
    coderay (1.0.8)
    erubis (2.7.0)
    fastercsv (1.5.5)
    hike (1.2.1)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (2.0.3)
      railties (>= 3.1.0, < 5.0)
      thor (~> 0.14)
    json (1.7.5)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    metaclass (0.0.1)
    mime-types (1.19)
    mocha (0.12.3)
      metaclass (~> 0.0.1)
    multi_json (1.3.7)
    mysql (2.8.1)
    mysql2 (0.3.11)
    net-ldap (0.3.1)
    pg (0.14.1)
    polyglot (0.3.3)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-openid (1.3.1)
      rack (>= 1.1.0)
      ruby-openid (>= 2.1.8)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.8)
      actionmailer (= 3.2.8)
      actionpack (= 3.2.8)
      activerecord (= 3.2.8)
      activeresource (= 3.2.8)
      activesupport (= 3.2.8)
      bundler (~> 1.0)
      railties (= 3.2.8)
    railties (3.2.8)
      actionpack (= 3.2.8)
      activesupport (= 3.2.8)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (10.0.0)
    rdoc (3.12)
      json (~> 1.4)
    rmagick (2.13.1)
    ruby-openid (2.1.8)
    shoulda (2.11.3)
    sprockets (2.1.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.6)
    test-unit (2.5.2)
    thor (0.16.0)
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.35)
    yard (0.8.3)

PLATFORMS
  ruby

DEPENDENCIES
  activerecord-jdbcmysql-adapter
  activerecord-jdbcpostgresql-adapter
  activerecord-jdbcsqlite3-adapter
  builder (= 3.0.0)
  coderay (~> 1.0.6)
  fastercsv (~> 1.5.0)
  i18n (~> 0.6.0)
  jquery-rails (~> 2.0.2)
  jruby-openssl
  mocha (= 0.12.3)
  mysql
  mysql2 (~> 0.3.11)
  net-ldap (~> 0.3.1)
  pg (>= 0.11.0)
  rack-openid
  rails (= 3.2.8)
  rdoc (>= 2.4.2)
  rmagick (>= 2.0.0)
  ruby-openid (~> 2.1.4)
  shoulda (~> 2.11)
  sqlite3
  test-unit
  yard

结果gem list

actionmailer (3.2.9, 3.2.8)
actionpack (3.2.9, 3.2.8)
activemodel (3.2.9, 3.2.8)
activerecord (3.2.9, 3.2.8)
activerecord-mysql2-adapter (0.0.3)
activeresource (3.2.9, 3.2.8)
activesupport (3.2.9, 3.2.8)
arel (3.0.2)
builder (3.0.0)
bundler (1.2.1)
coderay (1.0.8)
erubis (2.7.0)
fastercsv (1.5.5)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.0.3)
json (1.7.5)
mail (2.4.4)
metaclass (0.0.1)
mime-types (1.19)
mocha (0.12.3)
multi_json (1.3.7)
mysql (2.8.1)
mysql2 (0.3.11)
net-ldap (0.3.1)
pg (0.14.1)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-openid (1.3.1)
rack-ssl (1.3.2)
rack-test (0.6.2)
rails (3.2.9, 3.2.8)
railties (3.2.9, 3.2.8)
rake (10.0.0)
rdoc (3.12)
rmagick (2.13.1)
ruby-openid (2.1.8)
shoulda (2.11.3)
sprockets (2.2.1, 2.1.3)
sqlite3 (1.3.6)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
tzinfo (0.3.35)
yard (0.8.3)

结果bundle show

Gems included by the bundle:
  * actionmailer (3.2.8)
  * actionpack (3.2.8)
  * activemodel (3.2.8)
  * activerecord (3.2.8)
  * activeresource (3.2.8)
  * activesupport (3.2.8)
  * arel (3.0.2)
  * builder (3.0.0)
  * bundler (1.2.1)
  * coderay (1.0.8)
  * erubis (2.7.0)
  * fastercsv (1.5.5)
  * hike (1.2.1)
  * i18n (0.6.1)
  * journey (1.0.4)
  * jquery-rails (2.0.3)
  * json (1.7.5)
  * mail (2.4.4)
  * metaclass (0.0.1)
  * mime-types (1.19)
  * mocha (0.12.3)
  * multi_json (1.3.7)
  * mysql (2.8.1)
  * net-ldap (0.3.1)
  * pg (0.14.1)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-openid (1.3.1)
  * rack-ssl (1.3.2)
  * rack-test (0.6.2)
  * rails (3.2.8)
  * railties (3.2.8)
  * rake (10.0.0)
  * rdoc (3.12)
  * rmagick (2.13.1)
  * ruby-openid (2.1.8)
  * shoulda (2.11.3)
  * sprockets (2.1.3)
  * sqlite3 (1.3.6)
  * thor (0.16.0)
  * tilt (1.3.3)
  * treetop (1.4.12)
  * tzinfo (0.3.35)
  * yard (0.8.3)

答案1

如您所见Gemfile,Redmine 根据 Ruby 版本使用两个不同的 MySQL 适配器 gem。对于 Ruby 1.8,它使用 gem mysql,对于 Ruby 1.9,它mysql2使用 gem。

这两个 gem 需要在 中进行略微不同的配置database.yml,因为adapter名称与 gemname 相同。对于你的情况,你需要在 中将设置adapter为。mysqldatabase.yml

如果您配置了错误的适配器(即不可用的适配器),您会收到安装 gem 时经常出现的误导性错误消息activerecord-<configured adapter name>-adapter,而事实上,大多数情况下它被称为其他名称。

答案2

在 Redmine 根目录中运行bundle install可能会解决此问题。但我在您的帖子中没有看到您正在使用哪个版本的 Redmine 以及您要升级到哪个版本。如有疑问,请关注http://www.redmine.org/projects/redmine/wiki/RedmineUpgrade并且http://www.redmine.org/projects/redmine/wiki/RedmineInstall进行主要版本升级时。

答案3

经过一整个晚上的努力,我对 Gemfile 做了以下更改:

# platforms :mri_18, :mingw_18 do
#  group :mysql do
#    gem "mysql"
#  end
# end

platforms :mri_18, :mingw_18, :mri_19, :mingw_19 do
  group :mysql do
    gem "mysql2", "~> 0.3.11"
  end
end

然后运行

bundle update

相关内容