【问题标题】:Why I cannot do anything on new Rails App?(says mysql gem missing, but I am using default sqlite3)为什么我不能在新的 Rails 应用程序上做任何事情?(说缺少 mysql gem,但我使用的是默认 sqlite3)
【发布时间】:2021-03-13 21:57:43
【问题描述】:

在 Rails 中启动服务器后尝试执行任何操作时遇到此错误:

Puma caught this error: Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? mysql2 is not part of the bundle. Add it to your Gemfile. (LoadError)
 .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.2.7/lib/bundler/rubygems_integration.rb:334:in `block (2 levels) in replace_gem'
    .....

但是我没有在 database.yml 文件中使用 mysql 适配器,我已经使用默认数据库设置安装了 rails 应用程序。

这是否与我之前正在开发的应用程序有关,我们在那里使用 docker 和 mysql2。

宝石文件:

ruby '2.6.5'

gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
gem 'sqlite3', '~> 1.4'
gem 'puma', '~> 4.1'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.2'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

【问题讨论】:

  • 需要mysql的gem是什么?错误中说...请使用 Gemfile 进行更新。
  • 用 gemfile 更新了问题。我在想这是不是适配器的问题?因为我没有在 database.yml 文件中使用 mysql2 适配器,但是在错误中显示 Error loading 'mysql2' active record adapter
  • 安装mysql2,看看接下来会说什么。
  • 好的,我找到了解决方案,但我认为就是这样。将更新解决方案,谢谢

标签: mysql ruby-on-rails


【解决方案1】:

对于我正在处理的最后一个应用程序,我将 DATABASE_URL 环境变量设置为 mysql2,所以当我创建新应用程序时,rails 将我的默认数据库设置为该值,更多信息请参见下面的链接。

Found answer here.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2023-03-26
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    相关资源
    最近更新 更多