简体   繁体   中英

NoMethodError: undefined method `more_results' for #<Mysql>

I am trying to create rake task to import data from my old php application.But I can not connect to mysql database properly, when I run Old::User.all on rails console ,I get this error :

NoMethodError: undefined method `more_results' for #<Mysql>

        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:623:in `select'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:467:in `find_by_sql'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation.rb:64:in `to_a'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:143:in `all'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in `__send__'
        from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in `all'
        from (irb):1

Model class Old/user.rb

class Old::User < ActiveRecord::Base
  establish_connection "old_database"

  # Because table name is lowercase
  def self.table_name() 
    "user"
  end
end

database.yml

old_database:
  adapter: mysql
  database: old_database
  username: root
  password: 
  socket: /Applications/MAMP/tmp/mysql/mysql.sock

The latest MySQL gem (=>0.3.2) needs an additional gem to connect -- it's been architected just like the MSSQL-Server gem was in previous versions of Rails.

You also probably want to use the mysql2 (note the "2") gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM