can't activate sqlite3 (~> 1.3.6), already act

2019-03-11 14:50发布

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)

5条回答
We Are One
2楼-- · 2019-03-11 15:07

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.
查看更多
Evening l夕情丶
3楼-- · 2019-03-11 15:17

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
查看更多
相关推荐>>
4楼-- · 2019-03-11 15:21

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.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-11 15:21

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 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.

查看更多
我只想做你的唯一
6楼-- · 2019-03-11 15:29

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'
查看更多
登录 后发表回答