我创建了一个模型Tester
,整数列为tester_type
,并声明模型中的enum变量。Rails - 使用ActiveRecord :: Enum的参数错误
class Tester < ApplicationRecord
enum tester_type: { junior: 0, senior: 1, group: 2 }
end
我得到以下错误,而试图创建/初始化该模型中的对象:
ArgumentError: You tried to define an enum named "tester_type" on the model "Tester", but this will generate a class method "group", which is already defined by Active Record.
所以,我试图改变tester_type
到type_of_tester
但它抛出同样的错误:
ArgumentError: You tried to define an enum named "type_of_tester" on the model "Tester", but this will generate a class method "group", which is already defined by Active Record.
我已经搜索的解决方案,我发现这个错误是一个常数ENUM_CONFLICT_MESSAGE
在ActiveRecord::Enum类,但不能够找到这个问题的原因。
请帮帮我。
谢谢。
更改emum的名称,不要使用testers_type这已被rails使用。 – Sunny
我试着将它改为'type_of_tester',但是它抛出了相同的错误。 –
你也可以粘贴该错误。 – Sunny