【问题标题】:Could not load 'active_record/connection_adapters/mysql_adapter' add the necessary adapter gem to the Gemfile无法加载 'active_record/connection_adapters/mysql_adapter' 将必要的适配器 gem 添加到 Gemfile
【发布时间】:2019-03-23 22:16:17
【问题描述】:

使用此命令“git push dokku master”并在 Digital Ocean 上使用 Dokku 在 Rails 上部署 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

【问题讨论】:

  • 您可以发布您的 Gemfile 内容吗?
  • @lacostenycoder 我添加了 gem 文件确保向下滚动
  • enter code heregroup 是错字吗?你也真的需要git_sourcehackery block吗?
  • 抱歉,这是我在此处发布的类型,我进行了编辑。我不认为我需要 git_source。你认为问题出在这个@lacostenycoder

标签: ruby-on-rails ruby rubygems digital-ocean dokku


【解决方案1】:

您是否尝试使用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'

或者尝试将其移至开发组?只是尝试,不确定。

【讨论】:

  • 我认为问题不存在,但我尝试 sudo 得到“致命:目标路径 'mysql' 已经存在并且不是空目录。”我添加了 DATABASE_URL 但仍然遇到相同的错误并将其更改为 utf8 @lacostenycoder
【解决方案2】:

似乎 database.yml 不在正确的位置。 部署项目时,您可能应该手动放置 database.yml,因为该文件不在 repo 中。

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 2013-10-16
      • 2016-01-10
      • 2019-09-18
      • 2015-05-07
      • 2014-04-25
      • 1970-01-01
      • 2020-01-17
      • 2013-08-19
      相关资源
      最近更新 更多