2

我正在尝试遵循这个Redmine 设置教程。当我开始启动服务器时,我输入sudo rails server并收到以下错误:

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.) (LoadError)

我的 Gemfile 的相关部分内容如下:

....
if File.exist?(database_file)
database_config = YAML::load(ERB.new(IO.read(database_file)).result)
adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
if adapters.any?
  adapters.each do |adapter|
    case adapter
    when /mysql/
      gem "mysql", "~> 2.8.1", :platforms => [:mri_18, :mingw_18]
      gem "mysql2", "~> 0.3.11", :platforms => [:mri_19, :mingw_19]
      gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
...

并且 Gemfile.lock 包含 mysql2:

...
multi_json (1.5.0)
mysql (2.8.1)
mysql2 (0.3.11)
net-ldap (0.3.1)
...

我的 database.yml 文件包括以下内容:

...
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: ****
  password: ****

development:
  adapter: mysql2
  database: redmine_development
  host: localhost
  username: ****
  password: ****
  encoding: utf8
...

运行bundle install好像成功了,但是输出中没有列出mysql2,which mysql2什么都不返回,又bundle show mysql2返回Could not find gem 'mysql2' in the current bundle.

我已经卸载并重新安装了 mysql2 gem,每次都取得了明显的成功。

我已经阅读了关于其他 stackoverflow 问题的类似问题的描述,但他们的解决方案都没有解决我的问题。

4

1 回答 1

2

You will get this error if mysql2 is not included in the Gemfile.lock file that's generated by bundle. While the Gemfile is used to manage dependencies, the lock file is what is actually loaded by the rails app.

That's a more verbose Gemfile than I have seen before (I'm not generally familiar with Redmine)- where is this from? It doesn't appear to be from the most recent stable source. If you know you'll be using mysql2, I don't think there's any reason you need your Gemfile to parse your database config. For whatever reason, it's not properly reading the database.yml file.

Try adding gem 'mysql2' outside any blocks or loops and run bundle again.

于 2013-02-01T05:58:53.300 回答