Rails Setup: mysql2 gem always causing problems - mysql

I'm fairly new when it comes to commandline or Rails, but work on a rails project where I'm doing the frontend.
I've installed all gems that are needed for the project, but lately some errors occur when doing a rake:db migrate or today when trying to deploy the current version via cap production deploy
The problem I'm facing seems to have todo with the mysql2 gem. At least that is what the console says.
When running cap production deploy I get this error:
rake stdout: Nothing written
rake stderr: rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile.
and further down this …
Gem::LoadError: can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile.
What do I have todo here? When I do gem list I see that mysql2 is installed.
Thank you,
Matt

Rails used to have the mysql2 gem locked down to ~>0.3 in the codebase.
So that is what it looks for but your Gemfile will simply state
gem "mysql2"
Pretty sure they've updated this in the latest release of rails 4 so either:
Update to the latest version of rails 4 or use a specific version of the mysql2 gem
gem "mysql2", "~> 0.3.20"

Related

Error loading the 'mysql2' Active Record adapter

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

Warbler does not package Java/JRuby gems?

I have a Ruby on Rails app that I want to compile/package as a WAR file to host in Tomcat. I've added all of the relevant stuff I can find, but the WAR only appears to include the non-JRuby versions of gems. As a result, I get GemNotFound exceptions such as "could not find activerecord-jdbc-adapter" in Tomcat. If I open the WAR file in 7-zip, it does not show any of the JRuby or Java gems under /WEB-INF/gems/gems.
Warbler does not report any errors or warnings, and the WAR appears to contain everything it needs, except for these gems.
(Because this is a lightweight, internal app, I'm using sqlite for now... which explains the sqlite gems. The DB is stored outside the project and configured in the database.yml file.)
The relevant snippet from my Gemfile:
if defined?(JRUBY_VERSION)
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jruby-rack'
else
gem 'sqlite3'
end
I also tried explicitly including/excluding these gems in the warble.rb file:
config.gems -= ["sqlite3"]
config.gems += [
"jdbc-sqlite3",
"activerecord-jdbc-adapter",
"activerecord-jdbcsqlite3-adapter",
"jruby-openssl",
"jruby-rack",
"warbler"
]
As an interesting side note, if I modify my Gemfile to demand the JRuby gems, jruby -S bundle install works fine but warble gives a series of errors stating that the gems are only for use with JRuby. On the other hand, if I try to run it within JRuby (jruby -S warble) I get:
warble aborted!
no such file to load -- jruby_pageant
How can I convince Warbler that I want the JRuby gems?
Edit:
I also tried specifying platforms in the gemfile, as described in this blog post, but this causes warble to stack-overflow.
platforms :jruby do
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter', :require => false
gem 'activerecord-jdbcsqlite3-adapter', :require => false
gem 'jruby-openssl'
gem 'jruby-rack'
end
platforms :ruby do
gem 'sqlite3'
end
Versions:
ruby 1.9.3
jruby 1.7.4
warbler 1.3.8
So it turns out that I was missing the jruby-pageant gem. Once I added this to the bundle, jruby -S warble produced the expected output.

Rails application throughs MySql GEM error

I am trying to run the "Redmine" project management application written in Rails.
https://github.com/redmine/redmine
I downloaded it from Github and now while trying to run it (by double clicking on the rails file, I get this error in terminal:
Could not find gem 'mysql (~> 2.8.1) ruby' in the gems available on this machine
I have mysql 2.9.1 already installed.
I am new to the whole Rails thingy. I just installed it to be able to run this application.
So any advice on helping me run this app would be greatly appreciated.
Thanks
could it be that it doesnt work with the latest mysql version? make sure you stick this in your Gemfile in Rails app.
gem 'mysql', '~> 2.8.1'
also make sure its under test, or development if you want to run that locally.
group :test, :development do
gem 'mysql', '~> 2.8.1'
end
Probably easiest will be to tell Redmine to use your version of mysql:
Go to
\YourRedMineInstallFolder\apps\redmine\htdocs
open the Gemfile & Gemfile.lock and change/add this line at end or in mysql area.
gem "mysql", "~> 2.9.1"
Then go to the services and restart all redmine services specially ones with "..thin" in their name(This is pretty important).

This version of mysql2 (0.2.18) isn't compatible with Rails 3.1

Any help would be greatly appreciated, when I run the "generate model" command I get the following message:
WARNING: This version of mysql2 (0.2.18) isn't compatible with Rails 3.1 as the ActiveRecord adapter was pulled into Rails itself.
WARNING: Please use the 0.3.x (or greater) releases if you plan on using it in Rails >= 3.1.x
Is there a way to update the mysql2 version so it works with rails 3.1? or perhaps i could downgrade rails from 3.1 to 3.0?
You need to run
gem update mysql2
or add
gem "mysql2", "~> 0.3.11"
to your Gemfile and run bundle install
I had the same problem even after upgrading. It kept refusing to use 0.3.11 and defaulted back to the earlier version.
Finally figured out that in the Gemfile I had it written "< 0.3" instead of "> 0.3".
Kind of obscure (and dumb), but maybe it'll help someone.

Heroku error: Please install the postgresql adapter but I'm using mysql, so why am I seeing this error?

Please install the postgresql adapter: gem install activerecord-postgresql-adapter (pg is not part of the bundle. Add it to Gemfile.)
So I followed the instructions here: How to handle Ruby on Rails error: "Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'"
First of all, that doesn't fix my issue (causes other errors that I'd need to debug), but regardless, why should I have to install the PG interface for ruby exactly? I'm on mysql!
Edit: I've been told Heroku doesn't support MySQL. Was this a recent change? I was using mysql just about 3 months back for my Heroku site without any issues at all.
I don't want to presume anything but if you were able to work with heroku before, you probably had something like this in your Gemfile:
group :production do
gem 'pg'
....
end
group :development do
gem 'rspec-rails'
gem 'sqlite3'
....
end
This would ensure that rails is using mysql (or sqlite3 if you copy the example verbatim) in the development environment and postgres ('pg') on the production environment hosted by heroku. Give this a shot and see if it solves your problem. I hope it does.