In one of my application I am using Ruby 1.9.2, mysql2 gem, Rails 3.0.6.
While upgrading to Rails 3.1, getting following error throughout the application. When I ran command on console, then also getting same error:
ruby-1.9.2-p290 :003 > c = Cuisine.all
ArgumentError: wrong number of arguments (3 for 2)
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/mysql2-0.2.13/lib/ active_record/connection_ adapters/mysql2_adapter.rb: 585:in `select'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/connection_ adapters/abstract/database_ statements.rb:18:in `select_all'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/connection_ adapters/abstract/query_cache. rb:63:in `select_all'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/base.rb:470:in `find_by_sql'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/relation.rb:111: in `to_a'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/relation/finder_ methods.rb:155:in `all'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/activerecord-3.1.0/lib/ active_record/base.rb:441:in `all'
from (irb):3
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/railties-3.1.0/lib/ rails/commands/console.rb:45: in `start'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/railties-3.1.0/lib/ rails/commands/console.rb:8:in `start'
from /Users/ror/projects/ restaurant/highline/ruby/1.9. 1/gems/railties-3.1.0/lib/ rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Solution to fix the problem:
In Gemfile, replace 'mysql2' line with
gem 'mysql2', '>= 0.3'
and install mysql2 greater than '0.3' version, in my case it is ' mysql2 (0.3.6) ' and it will work :)
NOTE: as of Rails 0.3.0, and ActiveRecord 3.1 - the ActiveRecord adapter has been pulled out of mysql2 gem and into ActiveRecord itself. If you need to use mysql2 with Rails versions < 3.1 make sure and specify gem "mysql2", "~> 0.2.7" in your Gemfile
And for Rails version 3.1 or above use gem 'mysql2', '>= 0.3'
While upgrading to Rails 3.1, getting following error throughout the application. When I ran command on console, then also getting same error:
ruby-1.9.2-p290 :003 > c = Cuisine.all
ArgumentError: wrong number of arguments (3 for 2)
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from (irb):3
from /Users/ror/projects/
from /Users/ror/projects/
from /Users/ror/projects/
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Solution to fix the problem:
In Gemfile, replace 'mysql2' line with
gem 'mysql2', '>= 0.3'
and install mysql2 greater than '0.3' version, in my case it is ' mysql2 (0.3.6) ' and it will work :)
NOTE: as of Rails 0.3.0, and ActiveRecord 3.1 - the ActiveRecord adapter has been pulled out of mysql2 gem and into ActiveRecord itself. If you need to use mysql2 with Rails versions < 3.1 make sure and specify gem "mysql2", "~> 0.2.7" in your Gemfile
And for Rails version 3.1 or above use gem 'mysql2', '>= 0.3'