Closed
Description
When creating an enum property as following
class MyModel(models.Model):
class TextEnum(models.TextChoices):
VALUE0 = 'V0', 'Value 0'
VALUE1 = 'V1', 'Value 1'
VALUE2 = 'V2', 'Value 2'
txt_enum = EnumField(TextEnum, name='enum_field', null=True, blank=True, default=None)
It will generate a migration containing the following
operations = [
migrations.CreateModel(
name='MyModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('enum_field', django_enum.fields.EnumCharField(blank=True, choices=[('V0', 'Value 0'), ('V1', 'Value 1'), ('V2', 'Value 2')], default=None, max_length=2, null=True)),
],
options={
'constraints': [models.CheckConstraint(condition=models.Q(('txt_enum__in', ['V0', 'V1', 'V2']), ('txt_enum__isnull', True), _connector='OR'), name='entities_MyModel_txt_enum_TextEnum')],
},
),
]
Where the contraint is checking on the txt_enum
field and not on the named enum_field
field, resulting in migrations that will fail to execute