4

I am trying to upgrade my app and this is the error I am getting while deploying the app:

Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? can't activate mysql2 (< 0.6.0, >= 0.4.4), already activated mysql2-0.3.21. Make sure all dependencies are added to Gemfile.

here is my Gemfile: https://github.com/BI-CTSICN/sparc-request/blob/master/Gemfile

 gem 'mysql2', '~> 0.3.18'
 gem 'rails', '~> 5.1', '>= 5.1.4'

I am using ruby 2.4.2

mrzasa
  • 22,895
  • 11
  • 56
  • 94
Mohammad Shahbaz
  • 403
  • 8
  • 28

2 Answers2

4

Your mysql2 version you use (0.3.21, checked in Gemfile.lock) is too old, required one is newer than 0.4.4.

Upgrade your mysql2 gem by changing version in Gemfile and running bundle update mysql2. Of course before that check what changed between versions and then run your tests to check if upgrade didn't break anything.

mrzasa
  • 22,895
  • 11
  • 56
  • 94
  • so I need to put gem 'mysql2', '~> 0.4.4' in my gemfile and run bundle update ? – Mohammad Shahbaz Feb 07 '19 at 09:24
  • yup. replace current version with `0.4.4` – mrzasa Feb 07 '19 at 09:38
  • `0.4.4` is three years old – one year older than the Rails version the OP is using. Just out of curiosity: Why didn't you suggest using the latest version which would be [`0.5.2`](https://rubygems.org/gems/mysql2/versions) at the moment? – spickermann Feb 07 '19 at 14:51
  • Originally I suggested **newer than 0.4.4**: `required one is newer than 0.4.4. ` . In general it's easier to upgrade step-by-step - first to first working version, then to the newest. – mrzasa Feb 07 '19 at 14:54
  • @MohammadShahbaz please, consider upvoting it's worth even more than accepting – mrzasa Feb 08 '19 at 08:43
1

Just lock the mysql2 gem version not work for me. The only thing that work was match the rails gem version with mysql2 gem version, comparing both by it's release date.

Ex: I'm updating now my rails version from 5.1 to 5.2, so I want to put mysql 0.5.3 on my application (the most recent version). But I can put only the 0.4.10 version, because of it's release date match with rails 5.2.0.rc2 version that I installed right now (both are from march, 2018, with one day of difference).

I don't know why this working, but I guess that's a incompatibility problem between the rails and mysql2 versions that I tried to install.

Matheus Porto
  • 169
  • 1
  • 5