每次运行makemigrations时,Django模型的enum字段都会创建新的迁移,即使未更改 [英] Django model enum field creates new migrations every time makemigrations is run, even though unchanged

查看:52
本文介绍了每次运行makemigrations时,Django模型的enum字段都会创建新的迁移,即使未更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为用户首选项模型的一部分:

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

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

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?

推荐答案

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

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

这篇关于每次运行makemigrations时,Django模型的enum字段都会创建新的迁移,即使未更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆