ActiveRecord的并不在一个工作表中 [英] ActiveRecord doesn't work on one table
本文介绍了ActiveRecord的并不在一个工作表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Rails型号:
I have a Rails Model:
ruby-1.9.2-p0 > NavItem
=> NavItem(id: integer, item_identifier: string, description: string, description2: string, packing_unit: string, sales_unit_of_measure: string, ean_code: string, evp_price: string, item_category_code: string, class: string, product_group_code: string, maintenance_status: string)
如果我想创建一个记录:
If I want to create a record:
ruby-1.9.2-p0 > NavItem.create
NoMethodError: undefined method `has_key?' for nil:NilClass
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/attribute_methods/read.rb:69:in `class'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/persistence.rb:285:in `attributes_from_column_definition'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/locking/optimistic.rb:62:in `attributes_from_column_definition'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/base.rb:1396:in `initialize'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/base.rb:496:in `new'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/base.rb:496:in `create'
from (irb):20
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start'
from /Users/amueller/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我能做些什么?我有工作就好了其他车型。我不知道如何:(是否有任何保留字的列或做Rails的尝试应用这一公约上神奇的一些配置赶上这个错误?
What can I do? I have other Models which works just fine. I dont know how to catch this error :( Are there any reserved words in the columns or do Rails try to apply some configuration over convention magic on this?
我用Rails3使用Ruby 1.9.2。
I use Rails3 with Ruby 1.9.2.
推荐答案
正在使用类
(保留字)作为列名之一。如果改变了,你应该罚款。
You are using class
(a reserved word) as one of your column names. If you change that, you should be fine.
这篇关于ActiveRecord的并不在一个工作表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文