I hadn't manually created any instances of this model, but as usual, Rails creates fixtures for each new model including some dummy data. In this case, the non-null column was provided a value (Rails defaults to MyString
), however this field is an enum, so the string doesn't store to the database (where an enum is represented as an integer) so it comes through as null. The issue only occurs in test (and occurs in every test) because fixtures are loaded for each test into the database).
The solution is simple: Provide a valid enum value or remove unneeded fixtures!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…