我正在尝试为我的旧 rails 项目运行 rake db:setup 但出现以下错误。
`rake aborted!
Gem::LoadError: Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Caused by:
Gem::LoadError: mysql is not part of the bundle. Add it to your Gemfile.
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
(See full trace by running task with --trace)`
这是我的 ruby 版本ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
我的 Rails 版本Rails 4.2.7.1
和 mysql 版本mysql Ver 14.14 Distrib 5.5.56, for linux-glibc2.5 (x86_64) using readline 5.1
谢谢
答案1
尝试添加指定适配器是 mysql2(而不是 mysql)的行
adapter: mysql2
代替
adapter: mysql
在你的 config/database.yml 文件中
如果上述方法不起作用,则更新你的 Gemfile 并在那里明确添加 activerecord-mysql2-adapter 依赖项:
gem 'mysql2'
gem 'activerecord-mysql2-adapter'