replace_gem: Error loading the 'sqlite3' Active Record adapter - while creating model
Asked Answered
C

4

13

I am getting an error while creating a model in the created project and the error is as follows,

/home/sushmitha/.rvm/gems/ruby-2.5.1/gems/bundler-2.0.1/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem': 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. (LoadError)

Cheju answered 5/2, 2019 at 7:45 Comment(2)
run bundle in you're project directory and then try creating models.Bowles
@ray thank you it workedCheju
C
14

For reference only following is added here,

For Rails 5+, this issue is sort out by specifying the appropriate version for the sqlite gem in your Gemfile while working with an SQLite database:

 gem 'sqlite3', '~> 1.3', '>= 1.3.6'

Reference

Cigar answered 5/2, 2019 at 8:15 Comment(2)
Any reason why this wouldn't work? Same exact error, Rails 5+, but solution didn't work for me. Brand new application. Just basically ran rails new app_name and rails g scaffold ModelName name:textLewes
At least up until rails 5.2.2 this should be gem 'sqlite3', '~> 1.3.6'. Specifying '~> 1.3' as well will allow sqlite3 1.4 which will only be supported by rails 5.2.3. @Cigar gave the correct version specification in his comment above. Please also see (https://mcmap.net/q/743397/-brand-new-rails-app-can-39-t-generate-scaffold)Cube
U
18

For rails 5.2.2 explicitly , update your Gemfile to sqlite to:

gem 'sqlite3', '~> 1.3.6'

and in terminal use :

bundle update
Unprincipled answered 7/2, 2019 at 10:12 Comment(3)
Why? Where is this documented?Runkle
@Runkle I exactly don't remember where I saw that , I'm too a newbie , tried different versions and got on this one.Unprincipled
Every time I switched back to rails after some time, it surprises me in different waysFeer
C
14

For reference only following is added here,

For Rails 5+, this issue is sort out by specifying the appropriate version for the sqlite gem in your Gemfile while working with an SQLite database:

 gem 'sqlite3', '~> 1.3', '>= 1.3.6'

Reference

Cigar answered 5/2, 2019 at 8:15 Comment(2)
Any reason why this wouldn't work? Same exact error, Rails 5+, but solution didn't work for me. Brand new application. Just basically ran rails new app_name and rails g scaffold ModelName name:textLewes
At least up until rails 5.2.2 this should be gem 'sqlite3', '~> 1.3.6'. Specifying '~> 1.3' as well will allow sqlite3 1.4 which will only be supported by rails 5.2.3. @Cigar gave the correct version specification in his comment above. Please also see (https://mcmap.net/q/743397/-brand-new-rails-app-can-39-t-generate-scaffold)Cube
S
1

I have placed gem 'sqlite3', '~> 1.3.6' inside of group :deevelopment, :test do and it worked for me.

e.g :

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'sqlite3', '~> 1.3.6'
end
Shalondashalt answered 27/2, 2019 at 4:36 Comment(0)
C
0

Now that rails 5.2.2.1 has been released, the correct and also easiest fix is to bump rails to that version, as it will restrict sqlite3 to 1.3.6:

# In Gemfile
gem 'rails', '~> 5.2.2.1'

And then in the terminal

bundle install

Given the security fixes in that version, this should be done anyway.

Cube answered 18/3, 2019 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.