-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hii i got error cannot load such file #1047
Comments
config/database.yml default: &default |
This suggests your configuration is for |
Yes i tired change configuration, the result is same so i think is not about a config, cause with the another adapter like sqllite is running well. I try too with different language using mysql and works fine... what i made misatakes? By the way, two months ago everything works fine.. in my case its “rails new my_project -d mysql && cd my_project && rake db:create” and then no errors found while gem installed |
But this is exactly what I suggested to try. If different adapter name produce the error "cannot find mysql" then you are editing a different config file than your Rails instance is using. |
Have you got this working yet? I want to close out this ticket because it does not represent a bug in the mysql2 gem, but I want to confirm that you got the help you need. |
I'm actually seeing the same problem : The app refers to 'mysql' adapter when I have been verified there is no configuration other than for a 'mysql2' adapter. /vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': Could not load the 'mysql' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. (LoadError) I am fairly certain this is some bad mojo in Rails (5.2.3, MRI 2.5.1, macOS X) but just in case it is a mysql2 adapter issue, I thought I would chime in. |
OK - in my case, it looks like Rails is resolving the config to pull from ENV["DATABASE_URL"] and then preferring to infer 'mysql' from that versus the 'mysql2' (or 'sqlite3' ...) configured in the database.yml line 78 ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig#config:
and also line 163 ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver:
I would expect it to merge these two (as it seems to do for some non-adapter values) as I will be deploying using an Ops established ENV-based secrets mechanism to get that URL, so... it is definitely ActiveRecord 'resolving' the config wrong, and ignoring the mysql2 adapter setting ✅ |
Great find!! Do you think this is a Rails big, or at least documentation issue? |
The docs for ActiveRecord::Base#establish_connection 🔗 state that you can pass a hash "Or a URL" It does not say you can merge the two techniques. Furthermore, ActiveRecord encodes assumptions about the ENV["DATABASE_URL"] being definitive. It will actually populate the base configuration when ActiveRecord is first loaded, slurping the URL from the ENV variable before it even reads the YAML file. When AR resolves the URL, it basically overwrites any conflicting info you had specified in the YAML ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver#resolve_hash_connection
Any of the YAML settings OTHER THAN these uri-parsed fields will be merged OK.
So, that's the basics of why it does not work as I expected. The GOOD NEWS is that there is a simple hack to make DB URLs work with MySQL2:
Since ActiveRecord infers the URI scheme from the parsed URL as the adapter name,
If you CAN NOT change it (and I was laboring under that impression...) then :
Add this regex to the URL injection from ENV:
Which transforms the URI scheme, resulting in :
This works great, but it was a journey to get there, and as it turns out, SOME |
Hello there, |
@sci-phi, great explaination. wasted so much time to fix this but couldn't really do it. but you spotted it bang on. Thanks a ton. mine thing was working fine on local but while deploying, it was breaking |
@sci-phi thanks so much, i manage to fix this after days of debugging, this should be mentioned in the documentation clearly otherwise it will give an error pointing the developer to something that isn't wrong, which was a big problem in my experience |
my spec :
os: Mac os X mojave
mysql Ver 8.0.16 for osx10.14 on x86_64 Homebrew)
rvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
ruby version 2.6.1
rails version 5.2.3
i got error when try to run rake db:create 01:36:08
'rake aborted!
LoadError: Could not load the 'mysql' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.
/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
block in require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in
register' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:40:in
rescue in require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:26:in
require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
block in require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in
load_dependency'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:191:in
spec'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:956:in
establish_connection' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:60:in
establish_connection'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/railtie.rb:136:in
block (2 levels) in <class:Railtie>' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in
instance_eval'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in
block in execute_hook' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:62:in
with_execution_control'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:67:in
execute_hook' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:52:in
block in run_load_hooks'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in
each' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in
run_load_hooks'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/base.rb:328:in
<module:ActiveRecord>' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/base.rb:27:in
/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
block in require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in
register' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
block in require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in
load_dependency' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:17:in `block (2 levels) in '
Caused by:
'LoadError: cannot load such file -- active_record/connection_adapters/mysql_adapter
/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
block in require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in
register' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:40:in
rescue in require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:26:in
require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
block in require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in
load_dependency'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:191:in
spec'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:956:in
establish_connection' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:60:in
establish_connection'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/railtie.rb:136:in
block (2 levels) in <class:Railtie>' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in
instance_eval'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in
block in execute_hook' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:62:in
with_execution_control'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:67:in
execute_hook' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:52:in
block in run_load_hooks'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in
each' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in
run_load_hooks'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/base.rb:328:in
<module:ActiveRecord>' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/base.rb:27:in
/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in
block in require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in
register' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in
require_with_bootsnap_lfi'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in
require' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
block in require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in
load_dependency' /Users/maulana/.rvm/gems/ruby-2.6.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in
require'/Users/maulana/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:17:in `block (2 levels) in '
Caused by:
Bootsnap::LoadPathCache::FallbackScan:
any body can help ???
The text was updated successfully, but these errors were encountered: