0

我有一个在类中声明的常量的文件:

class LanguageChoices:
    EN = "English"
    FR = "French"

    @classmethod
    def choices(cls):
        return (
            (cls.EN, _("English")),
            (cls.FR, _("French")),
        )

还有我的模型:

from django.contrib.postgres.fields import ArrayField
from apps.users.constants import LanguageChoices

class Data(models.Model):
    language = ArrayField(
        models.CharField(
            max_length=30, choices=LanguageChoices.choices()), 
            blank=True, null=True
        )
    )

当我尝试运行迁移时,它会遇到此错误(即使我删除所有以前的迁移文件并使用新数据库也会发生这种情况):

SystemCheckError:系统检查发现了一些问题:

ERRORS:
users.Data.language: (postgres.E001) Base field for array has errors:
    'choices' must be an iterable containing (actual value, human readable name) tuples. (fields.E005)
ERROR: 1

有任何想法吗?

4

1 回答 1

0

好吧,结果代码很好,在中间的一个值(如 EN = "English",)之后有一个小逗号。VSCode 没有发出任何警告,我的视力给了我一些技巧,并把它隐藏起来。

于 2021-09-01T19:20:31.937 回答