Rails: 为数据库适配器指定了 'mysql2' 但未加载 gem

Rails: Specified 'mysql2' for database adapter but the gem is not loaded

显然有一个线程可以解决这个问题。但是我已经尝试 运行 解决方案中给出的那些命令。由于某种原因,我仍然遇到同样的错误。

我运行 gem install mysql2 -v 0.3.18

紧随其后 bundle install

在我的终端上。然后我通过键入启动服务器 rails 服务器

打开 localhost:3000。我收到同样的错误。

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).

如有任何帮助,我们将不胜感激。

将以下内容添加到您的Gemfile

gem 'mysql2', '~> 0.3.18'

然后运行:

bundle install