18
votes

Using ruby-1.9.2 and rails 3.2.1. The version of mysql2 is 0.2.7.

Upon running rake db:migrate I get the error: "undefined method `accept' for nil:NilClass:"

Trace includes:

gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'

7
Have you ever done a successful rake db:migrate, or is this a fresh install? Do any other rake commands work?Marc Talbot
Hi Marc, this is a fresh install - upgrade to 10.7 Mac OS X. Rake db:create worked fine.vectran
@vectran Did you fix this problem? I am facing same issue now.chhantyal

7 Answers

28
votes

Change your Gemfile from:

gem 'activerecord-mysql2-adapter'

to:

gem 'mysql2'
11
votes

Ok, I fixed on my machine. This is because of older MySQL2. Do this to resolve the problem.

bundle update mysql2

        Or

bundle update

For more details visit Github

10
votes

For me by removing gem 'activerecord-mysql2-adapter' from Gem File worked out

1
votes

Install the lastest mysql2 ruby gem. my environtment:

Rails3.2.9 + mysql2 0.2.9,  : "undefined method `accept' for nil:NilClass:"
Rails3.2.9 + mysql2 0.3.11, works fine
1
votes

It can happen because of incompatibility of your mysql and ruby version.

To resolve this either update your mysql gem by gem install mysql which will install latest mysql gem.

And then add this in your Gemfile.

If still the problem exists then you should see the compatibility between your ruby and mysql

0
votes

You get this if in your database.yaml file you have:

dev:
  adapter: mysql2

It should be (even if the gem you are using is mysql2):

dev:
  adapter: mysql

Took me over a week to figure this out I hope it saves you some time.

-1
votes

Define:

def nil.accept
  puts "Accepted."
end

And the error will go away.