rails 3中列名'type'的问题

Rah*_*ngh 2 mysql ruby-on-rails-3

我的一个表中有一个名为'type'的列.当我尝试像group.type一样访问它时,我收到以下错误:

super: no superclass method `type' for #<Group:0x000000035eaf30> 
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用迁移重命名列时,我收到以下错误

No such column: groups.type (migration failed)
Run Code Online (Sandbox Code Playgroud)

我尝试使用查询直接在mysql数据库中重命名列,但这也不起作用.

mysql> alter table groups change type group_type int(11);
ERROR 1054 (42S22): Unknown column 'type' in 'groups'
Run Code Online (Sandbox Code Playgroud)

请帮忙.

Chr*_*nig 11

该错误来自ActiveRecord附带的单表继承功能.告诉它使用不同的列type:

class Group < ActiveRecord::Base

  self.inheritance_column = "not_sti"

  #...
end
Run Code Online (Sandbox Code Playgroud)

这样,您就不必重命名该列.