无法加载 'active_record/connection_adapters/mysql_adapter' 将必要的适配器 gem 添加到 Gemfile

Could not load 'active_record/connection_adapters/mysql_adapter' add the necessary adapter gem to the Gemfile

使用此命令 "git push dokku master" 并在 rails 上使用 Dokku 在 Digital Ocean 上部署 ruby 时出现此错误

Could not load 'active_record/connection_adapters/mysql_adapter'. 
Make sure that the adapter in config/database.yml is valid. If you 
use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add 
the necessary adapter gem to the Gemfile.

我已经将 mysql2 添加到 Gemfile

gem 'mysql2', '~> 0.3.18'

gemfile 确保向下滚动:

source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
 end
 gem 'jquery-rails'
 gem 'rails', '~> 5.1.4'
 gem 'puma', '~> 3.7'
 gem 'sass-rails', '~> 5.0'
 gem 'uglifier', '>= 1.3.0'
 gem 'coffee-rails', '~> 4.2'
 gem 'turbolinks', '~> 5'
 gem 'jbuilder', '~> 2.5'
 group :development, :test do
   gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
   gem 'capybara', '~> 2.13'
   gem 'selenium-webdriver'
 end
group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'listen', '~> 3.1.5'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'bootstrap-sass', '~> 3.3.7'
gem 'devise', '~>4.2'
gem 'toastr-rails', '~> 1.0'
gem 'omniauth', '~> 1.6'
gem 'omniauth-facebook', '~> 4.0'
gem 'paperclip', '~>5.1.0'
gem 'aws-sdk','~> 2.8'
gem 'geocoder', '~> 1.4'
gem 'geocomplete_rails'
gem 'jquery-ui-rails', '~> 5.0'
gem 'ransack', '~> 1.7'
gem 'twilio-ruby', '~> 4.11.1'
gem 'fullcalendar-rails', '~> 3.4.0'
gem 'momentjs-rails', '~> 2.17.1'
gem 'stripe', '~> 3.0.0'
gem 'rails-assets-card', source: 'https://rails-assets.org'
gem 'omniauth-stripe-connect', '~> 2.10.0'
gem 'chartkick', '~> 2.2.4'
gem 'mysql2', '~> 0.3.18'
gem 'yaml_db'
gem 'vider'
gem 'nokogiri', '1.8.3'
gem 'rails_12factor'

我有database.yml

production:
  adapter: mysql2
  url: <%= ENV['DATABASE_URL'] %> 
  encoding: unicode
  pool: 5

我运行这个命令

dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql

捆绑包 v 是 1.16.3 我运行以下命令

bundle update
bundle install

预期的结果是使以下命令行工作,这将导致成功推送到服务器

git push dokku master

您是否尝试过 运行 使用 sudo 前缀?

sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql

你有任何错误吗?你也应该像这样设置编码:

production:
  adapter: mysql2
  encoding: utf8
  url: <%= ENV['DATABASE_URL'] %> 
  pool: 5

您还需要确保设置 DATABASE_URL 环境变量

dokku config:set DATABASE_URL=<some-db-url-here>

更新

阅读你的错误信息,也许你可以在 Gemfile 中尝试注释掉

gem 'mysql2', '~> 0.3.18'

或者尝试把它移到开发组?试试看,不确定。

看来 database.yml 不在正确的位置。 当你部署一个项目时,你可能应该手动放置 database.yml 因为这个文件不在 repo.

将 sql 更新为 gem 'mysql2','~> 0.4.10' 修复了问题