Ruby on Rails错误:为数据库适配器指定了“mysql2”,但未加载gem。将`gem'mysql2'添加到您的Gemfile中

时间:2015-10-12 16:15:37

标签: ruby-on-rails ruby ruby-on-rails-3 gem rubygems

好的,我已经阅读了无数关于同一问题的文章,我无法理解。我是Rails的新手,我不知道我在做什么,但每次运行rails服务器时都会收到此错误:

为数据库适配器指定了“mysql2”,但未加载gem。将gem 'mysql2'添加到您的Gemfile中(并确保其版本达到ActiveRecord所需的最低版本)。

require path_to_adapter
      rescue Gem::LoadError => e
        raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
      rescue LoadError => e
        raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.", e.backtrace
      end

我该怎么办?我已经完成了这两个线程的一切,但没有任何变化。

Gem::LoadError for mysql2 gem, but it's already in Gemfile

Rails: Specified 'mysql2' for database adapter but the gem is not loaded

1 个答案:

答案 0 :(得分:1)

与Rails 4有同样的错误。我在我的Gemfile中将mysql2 gem 0.4.x降级为0.3.20。然后运行bundle upgrade mysql2