加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql – 未定义的方法`eq’代表nil:nilClass with rails 3和r

发布时间:2020-12-11 23:37:47 所属栏目:MySql教程 来源:网络整理
导读:我不确定是什么原因引起了这个错误但是因为我在乘客中遇到了这个问题而现在在控制台中我也在想,也许mysql驱动程序是问题所在? 在osx / 10.6上,一切都按预期工作.它只是不会在Ubuntu 8.04上耐用. 我把问题钉在了“destroy”方法上,或者当我直接调用activerec

我不确定是什么原因引起了这个错误但是因为我在乘客中遇到了这个问题而现在在控制台中我也在想,也许mysql驱动程序是问题所在?
在osx / 10.6上,一切都按预期工作.它只是不会在Ubuntu 8.04上耐用.

我把问题钉在了“destroy”方法上,或者当我直接调用activerecord实例的方法时.为什么会这样?有任何想法吗?

系统:

> Ubuntu 8.04耐用.
> ruby?? 1.8.7(2010-04-19 patchlevel 253)[i686-linux],MBARI 0x8770,Ruby Enterprise Edition 2010.02
> rails 3.0.0-beta4
> mysql Ver 14.12 Distrib 5.0.51a,用于使用readline 5.2的debian-linux-gnu(i486)

这是错误输出

root@gehege:/var/www/foobar.com/api.foobar.com/v1# rake cleanup:status_cleanup RAILS_ENV=production --trace
(in /var/www/foobar.com/api.foobar.com/v1)
** Invoke cleanup:status_cleanup (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute cleanup:status_cleanup
rake aborted!
undefined method `eq' for nil:NilClass
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/persistence.rb:76:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/locking/optimistic.rb:110:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/callbacks.rb:278:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:412:in `_run_destroy_callbacks'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/callbacks.rb:278:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:230:in `destroy'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:202:in `transaction'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:285:in `with_transaction_returning_status'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:230:in `destroy'
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:8
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:6:in `each'
/var/www/foobar.com/api.foobar.com/v1/lib/tasks/cleanup.rake:6
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/ree/bin/rake:19:in `load'
/opt/ree/bin/rake:19

编辑:

即使在运行apt-get更新/升级到最新的hardy软件包并重新编译ree和mysql gem之后,我也会遇到同样的错误.

最佳答案 回答我自己的问题:经过一些研究后我发现rails(activerecord)需要映射到模型的表上的id字段.如果您使用链接表,则不需要它们 – 但对于您希望作为模型添加的表格,它们是.在我的情况下,解决方案是添加

set_primary_key :cal_id

其中cal_id是我唯一的密钥.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读