每次运行makemigrations时,Django模型枚举字段都会创建新的迁移,即使没有更改

时间:2017-09-15 17:36:38

标签: python django enums

作为用户偏好模型的一部分:

    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,
    )

每次运行makemigrations时,都会为此模型创建一个新的迁移文件,控制台输出为:

- Alter field email_frequency on profile

查看迁移文件,似乎每次迁移都是枚举字典的不同排列。任何想法为什么会发生这种情况?

1 个答案:

答案 0 :(得分:2)

EMAIL_FREQUENCY_CHOICES被定义为一个集合。它应该是一个列表或元组。