Ruby 迁移期间使用了错误的STI列
在新的迁移中,我尝试添加一列并填充其值:Ruby 迁移期间使用了错误的STI列,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,在新的迁移中,我尝试添加一列并填充其值: def up add_column :topics, :status, :string Topic.reset_column_information Topic.find_each do |t| if t.ended? t.status = 'ended' end end Topic.reset_column_information end 我不知道为什么,但在添加
def up
add_column :topics, :status, :string
Topic.reset_column_information
Topic.find_each do |t|
if t.ended?
t.status = 'ended'
end
end
Topic.reset_column_information
end
我不知道为什么,但在添加列之后,在Topic.find_期间,出现了以下异常:
单表继承机制无法定位子类:“其他”
我的主题模型确实声明了以下内容:
self.inheritance_column = 'class_name'
因此,我不确定为什么它仍然尝试使用type列查找STI子类。我发现,一旦我删除了
重置列信息,问题就消失了
add_column :topics, :status, :string
# Topic.reset_column_information
Topic.find_each do |t| ...
reset\u column\u information
在删除STI列设置时可能存在错误