gpt4 book ai didi

mysql - 加载错误: Error loading the 'mysql2' Active Record adapter [rails 5. 2.3]

转载 作者:行者123 更新时间:2023-11-29 15:44:11 51 4
gpt4 key购买 nike

我的rails应用程序使用的是ruby 2.6.3,rails 5.2.3,MySQL版本是5.7.27。当我尝试运行 rake db:create 时,rails 向我显示了错误:

rails aborted!
LoadError: Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? cannot load such file -- /path/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb
bin/rails:4:in `<main>'

Caused by:
LoadError: cannot load such file -- /path/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb
bin/rails:4:in `<main>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

这是我的 Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.2.3'
# Use mysql as the database for Active Record
gem 'mysql2', '0.5.2'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

# authentication
gem 'devise'
gem 'devise-i18n'

# admin
gem 'administrate'

gem 'haml-rails'
gem 'bootstrap'
gem 'jquery-rails'

group :development, :test do
gem 'rspec-rails'
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'better_errors'
gem 'pry-byebug'
gem 'pry-rails'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rubocop', require: false
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 chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

这是我的数据库配置:

# MySQL. Versions 5.1.10 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: name
password: password
host: localhost
port: 3306

development:
<<: *default
database: project_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: project_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: project_production
username: videomeeting
password: <%= ENV['PROJECT_DATABASE_PASSWORD'] %>

我还从 gem 列表中进行了检查,发现 mysql2 已经安装。您对这个错误有什么建议吗?提前致谢。

最佳答案

通过重新安装 activerecord gem 修复了此问题。

关于mysql - 加载错误: Error loading the 'mysql2' Active Record adapter [rails 5. 2.3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57263677/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com