I'm trying to build a Rails app around a pre-existing MySQL database. I created the rails project, set up the database.yml file properly and created one model, User, to correspond to my users table in the db. When I run the rails console to test it out however, this is what I get:
> User.all
(32.4ms) SHOW TABLES
(34.9ms) describe `users`
NoMethodError: undefined method `accept' for nil:NilClass
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_all'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/querying.rb:38:in `block in find_by_sql'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/explain.rb:40:in `logging_query_plan'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/querying.rb:37:in `find_by_sql'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/relation.rb:170:in `exec_queries'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/relation.rb:159:in `block in to_a'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/explain.rb:33:in `logging_query_plan'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/relation.rb:158:in `to_a'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/relation/finder_methods.rb:159:in `all'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/querying.rb:5:in `all'
from (irb):1
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
from /home/richard/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3-p0 :002 > ^C
Any idea why this might be? I'm following the rails convention as far as I'm aware: I made a User model to correspond with a table called users already in the db, whose primary key is an integer field called id.
Just had the same issue. Narrowed it to being a MySQL related issue since it was happening only in staging environment (MySQL) and not in the developpment one (sqlite3). Fixed it by upgrading the mysql2
from version 0.2.7 to 0.3.11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With