我的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的一个问题,参见此错误报告,将在下一个版本的rails 4.2.x中修复(感谢评论中的dcorr提供链接)。
在此期间,您可以通过将以下行添加到您的Gemfile中,降级为mysql2的0.3.18版本来解决该问题:
gem 'mysql2', '~> 0.3.18'
bundle update mysql2
- Pavanmysql2 (0.4.0)
是 Ruby gems 可以使用的最新版本,而且已经安装好了。 - newUserNameHeregem 'mysql2', '~> 0.3.18'
。 - newUserNameHere