踩坑mysql2。
问题描述
gemfile中添加了mysql2:
gem 'mysql2'
bundle
后,默认安装的是mysql2 0.5.0 。
database.yml
中,指定默认adapter为mysql2。
终端运行:rake db:create
出现报错,如下:
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).
其中,rails 5.1.2, ruby 2.3.6, macOS Sierra 10.12.3
解决方法
google后,找到了“Specified ‘mysql2’ for database adapter, but the gem is not loaded” when upgrading to 0.5.0, 版本问题,rails5.1.X与mysql2 0.5.0之间不兼容。
修改gemfile,指定版本为 0.4.10.
gem 'mysql2', '~> 0.4.10'
重新bundle
, OK .
参考
“Specified ‘mysql2’ for database adapter, but the gem is not loaded” when upgrading to 0.5.0