Rails 3中列名称为"type"的问题 [英] issue with column name 'type' in rails 3
本文介绍了Rails 3中列名称为"type"的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的一个表中有一列名为"type"的列.当我尝试像group.type一样访问它时,出现以下错误:
I have a columns named 'type' in one of my tables. When I try to access it like group.type, I got the following error:
super: no superclass method `type' for #<Group:0x000000035eaf30>
但是,当我尝试使用迁移来重命名列时,出现以下错误
However, when I try to rename the column using a migration, I get the following error
No such column: groups.type (migration failed)
我尝试使用查询直接在mysql数据库中重命名该列,但这也不起作用.
I tried to rename the column directly in the mysql db, using a query, but that doesn't work either.
mysql> alter table groups change type group_type int(11);
ERROR 1054 (42S22): Unknown column 'type' in 'groups'
请帮助.
推荐答案
该错误来自ActiveRecord附带的单表继承功能.只需告诉它使用不同于type
的列即可:
The error comes from the single table inheritance feature that comes with ActiveRecord. Just tell it to use a different column than type
:
class Group < ActiveRecord::Base
self.inheritance_column = "not_sti"
#...
end
有了它,您不必重命名列.
With that, you don't have to rename the column.
这篇关于Rails 3中列名称为"type"的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文