mysql2 gem 的 Gem::LoadError,但它已经在 Gemfile 中 [英] Gem::LoadError for mysql2 gem, but it's already in Gemfile
问题描述
Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded.
Add `gem 'mysql2'` to your Gemfile
加载以下文件时发生此错误:
This error occurred while loading the following files:
active_record/base
这是我在运行 rails 服务器时遇到的错误.
This is the error I get on running rails server.
The mysql2 gem has been added to the Gemfile as well.
我已经完成了bundle install
,并尝试重新启动服务器,但仍然出现错误.
I've done bundle install
, and tried restarting the server but still get the error.
推荐答案
如果您在升级到 rails 4.2.4(也有 rails 4.1.5)时遇到此错误,请尝试使用此版本的 mysql2:
If you have this error when upgrading to rails 4.2.4 (also with rails 4.1.5) try using this version of mysql2:
gem 'mysql2', '~> 0.3.18'
显然 mysql2 仍然与较新版本的 rails 不兼容,因为在我 2015 年 9 月 8 日回答这个问题时,rails 4.2.4 还很新,所以在您的 Gem 文件中使用上面的行并运行:
Apparently mysql2 isn't still compatible with newer version of rails because rails 4.2.4 is pretty new as the time of answering this question by me 8 September 2015 so use the above line in your Gem file and run:
bundle install
你应该没事了
这篇关于mysql2 gem 的 Gem::LoadError,但它已经在 Gemfile 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!