I am writing a command-line app that uses active_record for database interactions. I currently support only postgres, but I want to allow sqlite3 as well. I added a line to my gemspec file to add sqlite3 as a runtime dependency and ran bundle
, but when I try to run the app via rspec, I get the following error:
LoadError:
Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.4), already activated sqlite3-2.0.2-x86_64-linux-gnu. Make sure all dependencies are added to Gemfile.
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:14:in `<top (required)>'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/abstract/connection_handler.rb:333:in `resolve_pool_config'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/abstract/connection_handler.rb:134:in `establish_connection'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_handling.rb:53:in `establish_connection'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-import-1.7.0/lib/activerecord-import/import.rb:256:in `establish_connection'
I have also tried putting the ‘sqlite3-ruby’ gem in the gemspec, but I get the same error. I understand that AR 7.1 includes sqlite3, but does that mean I don’t need the gem in my gemspec file? I tried removing it, but get a similar error:
LoadError:
Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile.
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:14:in `<top (required)>'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/abstract/connection_handler.rb:333:in `resolve_pool_config'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_adapters/abstract/connection_handler.rb:134:in `establish_connection'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.3/lib/active_record/connection_handling.rb:53:in `establish_connection'
# ./vendor/bundle/ruby/3.2.0/gems/activerecord-import-1.7.0/lib/activerecord-import/import.rb:256:in `establish_connection'
So it seems it is needed.
Any ideas what I’m doing wrong?