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

rails不能在model中使用type作为字段名的解决办法

发布时间:2020-12-17 04:06:38 所属栏目:百科 来源:网络整理
导读:使用type作为字段名会出现这个错误: ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'xxxx'. This error is raised because the column 'type' is reserved for storing the class in case of in

使用type作为字段名会出现这个错误:

ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'xxxx'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite SmsRecord.inheritance_column to use another column for that information.


解决办法:

在相关model中加入“self.inheritance_column = nil”即可,如:

class SmsRecord < ApplicationRecord
	self.inheritance_column = nil
end


-------------------------------- 作者在 2018-04-01 21:46:38 补充以下内容 --------------------------------

相关参考:

https://stackoverflow.com/questions/11984893/issue-with-column-name-type-in-rails-3

https://stackoverflow.com/questions/7134559/rails-use-type-column-without-sti

https://apidock.com/rails/ActiveRecord/ModelSchema/ClassMethods/inheritance_column

(编辑:李大同)

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

    推荐文章
      热点阅读