18

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'

vectran
  • 1,961
  • 1
  • 14
  • 17

7 Answers7

28

Change your Gemfile from:

gem 'activerecord-mysql2-adapter'

to:

gem 'mysql2'
Shaheen Ghiassy
  • 7,397
  • 3
  • 40
  • 40
11

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

chhantyal
  • 11,874
  • 7
  • 51
  • 77
10

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

Anikethana
  • 350
  • 3
  • 11
1

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
Siwei
  • 19,858
  • 7
  • 75
  • 95
1

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

Akshay Mohite
  • 2,168
  • 1
  • 16
  • 22
0

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.

leat
  • 1,418
  • 1
  • 15
  • 21
-1

Define:

def nil.accept
  puts "Accepted."
end

And the error will go away.

Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74
  • hilarious, I hope not too many people will fall into the trap. might not be well received in a Q/A helping site – Mathieu J. Jun 12 '20 at 02:58