Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

Hi i am using rails version 3.0.7 when i run rails generate model task name:string i m getting following warning

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/railtie.rb:59
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:1904
    from /home/sun/railsapp/dog/vendor/plugins/attribute_fu/init.rb:1
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/plugin.rb:81
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
    from /home/sun/railsapp/dog/config/environment.rb:5
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require_environment!'
    from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:16
    from script/rails:6:in `require'
    from script/rails:6

when i try to install activerecord-mysql2-adapter by :gem install activerecord-mysql2-adapter ERROR: Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository

please help me thanks

like image 677
Jagdish Barabari Avatar asked Apr 30 '11 09:04

Jagdish Barabari


4 Answers

The problem is because you are trying to install the latest version of mysql2 which is incompatible with rails 3.0.x version

SO, in your Gemfile change the line for mysql2 gem for this:

gem 'mysql2', '< 0.3'

then bundle command

and then when the new mysql2 gem file ( i think is 0.2.7 ) you will solve the problem.

like image 152
eveevans Avatar answered Nov 19 '22 23:11

eveevans


if still not working try this too:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Users/YOUR_USER_NAME/.rvm/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
like image 42
jstnno Avatar answered Nov 19 '22 21:11

jstnno


gem 'mysql2', '< 0.3' is the only way on Rails 3.0.7 (before 3.1)

UPDATE: sorry, that was not the case also, did't work either, there is a better way:

vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.2/lib/active_record/connection_adapters$[rails307]$ ls em_mysql2_adapter.rb mysql2_adapter.rb

take mysql2_adapter.rb file from mysql2 gem version 0.2.x and copy it to the above location

now it works for me with just gem 'mysql2' in Gemfile

like image 1
rubyconvict Avatar answered Nov 19 '22 21:11

rubyconvict


After trying the solution offered by @eveevans I was still having version issues. Then reading the suggestion by @rubyconvict, I thought instead about using the -v option for gem rather than pushing files about.

Here's what I found eventually resolved my struggle with the dreaded "version of mysql2 (0.3.2)" message on DreamHost:

# in mysql, create example_app & example_app_test ...
# ... for the purposes of this example only, production == development db
rails new example_app --database=mysql --freeze
cd example_app
vim config/database.yml
#   change settings for host, user, password ...
#   ... database for test (example_app_test) ...
#   ... & database for production & development (example_app)

vim Gemfile
#   gem 'mysql2', '< 0.3'

gem uninstall mysql2        # if installed: gem list -d mysql2
gem install mysql2 -v 0.2.7 
rake db:migrate     

From there, I can move onto other RoR fun, like perhaps modifying routes (vim config/routes.rb ... however your mileage may vary).

like image 1
Dean Peters Avatar answered Nov 19 '22 23:11

Dean Peters