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