在我的gemfile中,我有:
gem 'mysql2'
我的database.yml如下:
default: &default
adapter: mysql2
database: <%= ENV['db_name'] %>
username: <%= ENV['db_user'] %>
password: <%= ENV['db_pass'] %>
host: <%= ENV['db_host'] %>
pool: 32
socket: <%= ENV['socket'] %>
development:
<<: *default
production:
<<: *default
我同时运行过bundle update
和bundle install
,并且我的Gemfile.lock显示mysql2。
但是,当我运行rake db:migrate
时,我在我的计算机和临时服务器上都得到了如下结果:
myproject.com(master)$ rake db:migrate
WARNING: Use strings for Figaro configuration. 10000012508 was converted to "10000012508".
WARNING: Use strings for Figaro configuration. 860526407370038 was converted to "860526407370038".
rake aborted!
Gem::LoadError: 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).
.....
为了确保不存在mysql2的坏版本,我执行了bundle clean --force
,并再次运行bundle install
和bundle update
,当我运行gem list
时,我看到的是mysql2 (0.4.0)
,没有其他版本。
任何想法都将不胜感激。
解决方案
这是目前Rails 4.1.x和4.2.x的一个问题,根据这个bug report,它将在rails 4.2.x的下一个版本中修复(在链接的评论中归功于dcorr )。
同时,你可以通过降级到mysql2的0.3.18版本来修复,方法是将下面这行代码添加到gemfile中:
gem 'mysql2', '~> 0.3.18'
发布于 2015-09-16 21:46:34
这个问题与发布时间和使用的Rails版本相关,这个问题的答案是,这个问题是由执行bundle update
和您的mysql2版本更新到0.4.x引起的,该版本与最新的Rails ActiveRecord存在不兼容问题。
同样,请注意,这不是使用旧版本Rails / ActiveRecord的人的解决方案。
快速的解决方案是简单地在gemfile中指定mysql2
版本,如下所示:
gem 'mysql2', '0.3.20'
长期的解决方案是等待ActiveRecord的更新或mysql2中的某些内容发生变化。
发布于 2016-04-02 14:50:55
如果你能够升级你的rails版本,那么把你的Gemfile改成这样就可以在不降级mysql2 gem版本的情况下解决这个问题:
gem 'rails', '4.2.6'
发布于 2015-09-08 20:25:15
当您的机器上缺少一些mysql包时,通常会发生这种情况。你有没有从gem install mysql2
得到任何错误?您使用的是什么操作系统?
如果是在debian或ubuntu上,试试sudo apt-get install libmysqlclient-dev
。
还要确保gem没有放在Gemfile的group
语句中。
https://stackoverflow.com/questions/32457657
复制相似问题