我无法加载我的 'mysql2' gem. [英] I cannot load my 'mysql2' gem.

查看:32
本文介绍了我无法加载我的 'mysql2' gem.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rails 的初学者,当我在终端中输入rails server"时,收到此错误:

I am a beginner at Rails and when I typed in 'rails server' in Terminal, I received this error:

Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

我使用的是 OSX Yosemite 10.10.5.我试过安装它:

I am using OSX Yosemite 10.10.5. I've tried installing it:

gem install mysql2

它仍然给了我同样的错误.我看到安装了mysql2-0.4.0.请帮忙,谢谢!

It still gave me the same error. I see that mysql2-0.4.0 is installed. Please help, thank you!

推荐答案

Rails 4.2.4 及更早版本有一个 bug,随着 mysql2 gem 新发布的 0.4.0 版本——Rails 的一部分会不小心拒绝使用最新发布的 0.4.0 版本的 mysql2.

There is a bug in Rails 4.2.4 and previous, with the newly released 0.4.0 version of the mysql2 gem -- one part of Rails will accidentally refuse to use the newly released 0.4.0 version of mysql2.

这里报告了这个问题,虽然没有很多细节:

The issue is reported here, although without a lot of details:

https://github.com/rails/rails/issues/21544

直到发布以某种方式修复此问题的新版本 Rails 之前,将其添加到您的 Gemfile 中,指定 mysql2 0.4.0 将不起作用:

Until a new version of Rails is released that fixes this one way or another, add this to your Gemfile, specifying that mysql2 0.4.0 won't work:

 # mysql 0.4.0 does not work with Rails 4.2.4
 # https://github.com/rails/rails/issues/21544
 gem 'mysql2', '>= 0.3.13', '< 0.4.0'

您之前的 Gemfile 中可能只有 gem 'mysql2' -- 添加上述版本约束,因此它知道 0.4.0 将不起作用.添加注释以便您知道为什么要这样做,并且可以在以后不再需要时将其删除(可能在 Rails 4.2.5 发布时).

You previously probably just have gem 'mysql2' in your Gemfile -- add the version constraints as above, so it knows 0.4.0 won't work. Add the comments so you know why you did it, and can remove it later when no longer neccesary (probably whenever Rails 4.2.5 comes out).

像上面一样编辑应用程序中的 Gemfile,然后在应用程序目录中运行 bundle update mysql2,这样您的应用程序将再次使用 mysql2 gem 版本 0.3.x,正如当前 Rails 版本所希望的那样.

Edit the Gemfile in your app like above, and then run bundle update mysql2 in your app directory, so your app will be using a mysql2 gem version 0.3.x again, as current Rails version wants.

当 Rails 4.2.5 或更高版本出来并且你升级到它时,你可能想回到你的 Gemfile 并删除 mysql2 的版本要求规范,返回它说只是 gem 'mysql2' 再次.因此,一旦 Rails 也愿意,您的应用程序将愿意使用较新的 mysql2 0.4.0 gem.

When Rails 4.2.5 or later comes out and you upgrade to it, you will probably want to go back to your Gemfile and remove the version requirement specification for mysql2, return it to saying just gem 'mysql2' again. So your app will be willing to use the newer mysql2 0.4.0 gem, once Rails is willing to do so too.

这篇关于我无法加载我的 'mysql2' gem.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆