【问题标题】:'choices' must be an iterable containing (actual value, human readable name)'choices' 必须是一个可迭代的包含(实际值,人类可读的名称)
【发布时间】:2021-01-20 09:39:01
【问题描述】:

我正在尝试进行迁移,但我不能。

代码:

from .setting import WORK_TYPE,USER_ACCOUNT

class Rating (models.Model):
    RATING_CHOICES = (
    ('poor','Poor'),
    ('average', 'Average'),
    ('good', 'Good'),
    ('verygood', 'Very Good'),
    ('excellent', 'Excellent')
),
    rating = models.CharField(max_length=30,choices=RATING_CHOICES, default='poor')
    create_at=models.DateTimeField(auto_now_add=True)
    update_at=models.DateTimeField(auto_now=True)

这给出了错误:'choices' must be an iterable containing (actual value, human readable name)

【问题讨论】:

    标签: python django-models


    【解决方案1】:

    您忘记了选择的括号,您的代码应该是:

    RATING_CHOICES = [(
    ('poor','Poor'),
    ('average', 'Average'),
    ('good', 'Good'),
    ('verygood', 'Very Good'),
    ('excellent', 'Excellent')
    ),]
    

    Model Choice documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 2018-07-21
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 2015-04-16
      相关资源
      最近更新 更多