作为用户偏好模型的一部分:
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
查看迁移文件,似乎每次迁移都是枚举字典的不同排列。任何想法为什么会发生这种情况?
答案 0 :(得分:2)
EMAIL_FREQUENCY_CHOICES
被定义为一个集合。它应该是一个列表或元组。