Django model enum field creates new migrations eve

2020-04-10 01:14发布

As part of a user preferences model:

    DAILY = "d"
    WEEKLY = "w"
    FORTNIGHTLY = "f"
    MONTHLY = "m"
    DISABLE = "x"
    EMAIL_FREQUENCY_CHOICES = {
        (DAILY, 'Daily'),
        (WEEKLY, 'Weekly'),
        (FORTNIGHTLY, 'Fortnightly'),
        (MONTHLY, 'Monthly'),
        (DISABLE, 'Disabled'),
    }
    email_frequency = models.CharField(
        max_length=1,
        choices=EMAIL_FREQUENCY_CHOICES,
        default=WEEKLY,
    )

Every time I run makemigrations a new migration file is created for this model, with console output of:

- Alter field email_frequency on profile

Looking at the migration files, it seems like each migration is a different permutation of the enum dictionary. Any ideas why this is happening?

1条回答
够拽才男人
2楼-- · 2020-04-10 01:54

EMAIL_FREQUENCY_CHOICES is defined as a set. It should be a list or tuple.

查看更多
登录 后发表回答