76

I’m using Ubuntu and run into to a problem when using db:migrate for ruby project.

rails aborted!
LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile.
/home/juan/odin_on_rails/RailsaAPP/bin/rails:9:in `<top (required)>'
/home/juan/odin_on_rails/RailsaAPP/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
Gem::LoadError: can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile.
/home/juan/odin_on_rails/RailsaAPP/bin/rails:9:in `<top (required)>'
/home/juan/odin_on_rails/RailsaAPP/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
skalee
  • 12,331
  • 6
  • 55
  • 57
Juan Rodriguez
  • 761
  • 1
  • 5
  • 3
  • Welcome to Stack Overflow! Please read [what this site is about](https://stackoverflow.com/about) and "[How to ask](https://stackoverflow.com/questions/how-to-ask)" before asking a question. – SivolcC Feb 05 '19 at 04:40
  • Guessing but I think ActiveRecord only works with specific versions and with the recent release of 1.4 you get this error. – Kris Feb 07 '19 at 12:52
  • This also manifests as `Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).` if sqlite is in gemspec. – Kris Feb 07 '19 at 16:04

5 Answers5

102

I had a similar issue today. Here's what worked for me. I tried using Michael's approach but received a similar error.

So instead, I removed the gem that I thought was giving me an error, by gem uninstall sqlite3 -v 1.4.0

and instead, used in my gem file. gem 'sqlite3', '~> 1.3.6' Ran the bundle update and it worked like a charm for me.

Saral Karki
  • 1,021
  • 1
  • 8
  • 7
69

I solved this error configuring the version of sqlite3 in the Gemfile like this:

gem 'sqlite3', '~> 1.3', '< 1.4'

It seemed that sqlite3-1.3.6 is not working fine and the sqlite3-1.4 is not supported yet, so it(the line I suggest to correct for this problem) will download the latest 1.3 version. In my case it is the sqlite3-1.3.11.

I am using rails-5.0.0 and ruby-2.5.1 in my project.

barlop
  • 12,887
  • 8
  • 80
  • 109
cavalcanteg
  • 802
  • 5
  • 13
  • 2
    Worked like a charm. FYI... I am using mac (osx 10.13.2), rails 5.2.2, ruby 2.6 with all dev done in RubyMine. – zevij Feb 10 '19 at 17:35
  • Works great! Using Rails 5.2.2 and Ruby 2.6.1. – cyber_dave Feb 21 '19 at 20:48
  • 4
    The dependency version is hardcoded in ActiveRecord's adapter for Sqlite3 for 5.2.2 as ```gem "sqlite3", "~> 1.3.6"``` – rudygodoy Mar 14 '19 at 20:06
  • Won't that ~> 1.3 automatically make it < 1.4 , so I guess could omit that < 1.4 part since it's implied. Also I don't know why you say the latest 1.3 was 1.3.11 . You posted your answer on Feb 7th and the latest 1.3 is https://rubygems.org/gems/sqlite3/versions/ . 1.3.13 which came out in Jan 2017. Long before you wrote your answer and claimed the latest was 1.3.11 So not sure why you thought it was 1.3.11 ?! Scaly's line is a bit less superfluous and works `gem 'sqlite3', '~> 1.3.6'` and `gem sqlite3 '1.3.13'` works , which is the latest 1.3 – barlop Mar 21 '19 at 12:15
35

The problem is caused by Active Record which has version constraint on sqlite3 gem. For example, in case of Rails 5.2.2 (latest stable release at the time I am writing this response) it is ~> 1.3.6. However, this constraint is not specified in gemspec, but in a source file which contains the adapter class. As a consequence, Bundler is unaware of it, and installs sqlite3 gem version 1.4.0, which is conflicting.

The good news is that fix has been already merged into master and Rails 5.2 maintenance branches (and possibly other ones), and should be included in 5.2.3.

For now, you can do one of following:

  • Add sqlite3 constraint to your Gemfile: gem 'sqlite3', '~> 1.3.6'
  • Install Active Record from a branch named 5-2-stable.
skalee
  • 12,331
  • 6
  • 55
  • 57
  • How might one do the second option? – Marshall Davis Mar 12 '19 at 06:41
  • I guess instead of `gem 'sqlite3', '~> 1.3.6'` . one may as well just specify the latest 1.3 listed https://rubygems.org/gems/sqlite3/versions/ . So `gem sqlite3 '1.3.13'`? – barlop Apr 01 '19 at 18:28
  • @ToothlessRebel `gem "activerecord", github: "rails/rails", branch: "5-2-stable"`. Though you may need to install some other Rails gems from Git as well. @barlop Yes, depending on what you actually want. – skalee May 02 '19 at 14:50
13

None of the solution worked for me, so i traced the error and located the connection adapters

Location:

C:\Ruby\lib\ruby\gems\2.5.0\gems\activerecord-5.2.2\lib\active_record\connection_adapters\

File:

sqlite3_adapter.rb

changed

gem "sqlite3", "~> 1.3.6"

to

gem "sqlite3", "~> 1.4.0"

I refreshed my webpage and everything works!!!

My Env

Windows 10
Ruby : 2.5.3-p105
Rails: 5.2.2
femotizo
  • 1,135
  • 2
  • 12
  • 18
7

Looks like sqlite3 version in the system is different from that installed in the application. In this case, you can update a gem version for your app:

bundle update sqlite3

Or change gem version in Gemfile:

gem 'sqlite3', '~> 1.4'
Michael Arkhipov
  • 737
  • 8
  • 19
  • Almost. I had to use the version after _can't activate sqlite3 (~> x.x.x)_ in the brackets in the Gemfile. – qwerty_so Dec 07 '19 at 19:27