Cannot activate mysql2 (~> 0.3.6), mysql2-0.3.2 is already activated in Rails 3.1

I am just trying to get the most basic shell of a rails application running under 3.1, and I get this strange error when I run bundle exec rake db: migrate -

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.) 

All the messages I read here and elsewhere say that I should use the new mysql2 adapter for rails 3.1, so I have

 gem 'mysql2', '0.3.2' 

in my gemfile. Some posts suggested using -

 gem 'mysql2', '~> 0.3' 

but it causes the same error. Gemstone set to -

 /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/mysql2-0.3.2 

It has been suggested that I will again include this line in my gemfile, this time -

 gem 'mysql2', '< 0.3' 

but when I do this, start installing the package, and then try migrations again, I get -

 An error has occurred, all later migrations canceled: undefined method `rows' for nil:NilClass 

My complete migration file is as follows:

 class CreatePlaces < ActiveRecord::Migration def change create_table :places do |t| t.string :title t.string :meta_description t.string :permalink, :limit => 60 t.string :name, :limit => 60 t.string :address t.string :state, :limit => 2 t.string :region, :limit => 3 t.float :latitude t.float :longitude t.text :description t.boolean :active, :default => true t.timestamps end add_index :places, [:permalink, :state, :region, :latitude, :longitude, :active], :name => 'places_index' end end 

And the full conclusion of this migration is

 == CreatePlaces: migrating =================================================== -- create_table(:places) -> 0.0925s -- add_index(:places, [:permalink, :state, :region, :latitude, :longitude, :active], {:name=>"places_index"}) -> 0.1097s == CreatePlaces: migrated (0.2023s) ========================================== rake aborted! An error has occurred, all later migrations canceled: undefined method `rows' for nil:NilClass 

There are no later migrations, this is the only one, because this is the application that I'm just starting to try to run Rails 3.1 correctly. Removing the database and re-creating it brings me to the same place.

I can access Places from the console -

 ruby-1.9.2-p180 :001 > Place (0.3ms) SHOW TABLES (0.1ms) SHOW TABLES (1.1ms) describe `places` => Place(id: integer, title: string, meta_description: string, permalink: string, name: string, address: string, state: string, region: string, latitude: float, longitude: float, description: text, active: boolean, created_at: datetime, updated_at: datetime) 

But when I actually try to find any find or something in Places, I get the following error:

 Place.find(:all) ArgumentError: wrong number of arguments (3 for 2) from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/database_statements.rb:9:in `select_all' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:470:in `find_by_sql' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/relation.rb:111:in `to_a' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:155:in `all' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:105:in `find' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:437:in `find' from (irb):2 from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:45:in `start' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:8:in `start' from /Users/mark/.rvm/gems/ ruby-1.9.2-p180@rails310pre /gems/railties-3.1.0.rc5/lib/rails/commands.rb:40:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' 

Does anyone have any ideas? I’ve been digging for 18 hours and just running in circles.

Thanks, --Mark

+6
source share
3 answers

Active Record has its own requirements compatible with mysql2 versions. Here's a line of code for Rails 3.1. You must use a version of mysql2 that satisfies these requirements.

Please install mysql2 adapter: gem install activerecord-mysql2-adapter (cannot activate mysql2 (~> 0.3.6), mysql2-0.3.2 is already activated. Make sure all dependencies are added to the Gemfile.)

This suggests that Rails expects a version of mysql2 that is greater than 0.36 and less than 0.4, but the version found is 0.3.2. If you modify your Gemfile to request a version in this range, then Active Record should be happy. Maybe,

 gem 'mysql2', '0.3.6' 

Remember to update your kit after modifying the gemfile.

 bundle update mysql2 
+7
source

It also made me pull my hair out. The only reasonable solution I could get was to switch to the main gem mysql2 branch.

gem 'mysql2' ,: git => 'git: //github.com/brianmario/mysql2.git'

After this update, the Rails 3.1.0.rc5 application may start with MySQL. (During this post, the latest version of the gem was 0.3.6)

+1
source

Pretty old question, so I guess the original poster has already solved the problem. However, if someone comes to this post trying to solve the first problem:

Please install mysql2 adapter: gem install activerecord-mysql2-adapter (cannot activate mysql2 (~> 0.3.6), mysql2-0.3.2 is already activated. Make sure all dependencies are added to the Gemfile.)

This is most likely because you are not performing your migrations through bundle exec. Try running bundle exec rake db:migrate .

0
source

Source: https://habr.com/ru/post/893559/


All Articles