[英]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 : 我正在尝试创建rake任务以从旧的php应用程序导入数据。但是,当我在rails控制台上运行Old :: User.all时,我无法正确连接到mysql数据库,出现此错误:
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 模型类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. 最新的MySQL gem(=> 0.3.2)需要一个额外的gem进行连接-就像在Rails以前版本中的MSSQL-Server gem一样,它的架构也是如此。
You also probably want to use the mysql2 (note the "2") gem 您可能还想使用mysql2(请注意“ 2”)gem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.