我在下面创建了这个模型,几乎整个星期我都工作得很好。关闭服务器并再次重新启动它,它向我抛出了 (fields.E005) 'choices' must be an iterable contains (actual value, human url url name) tuples 错误。完全使用了django文档,仍然没有解决方案。
`类检查(模型.模型):
RESULT_CHOICES = [
("PR" "Passed"),
("PR" "Passed with minor Defects"),
("PR" "Passed with major Defects"),
("FR" "Failed due to minor Defects"),
("FR" "Failed due to major Defects"),
("FR" "Failed"),
]
vin_number = models.ForeignKey(Vin, on_delete=models.CASCADE, related_name='inspections')
inspection_number = models.CharField(max_length=20)
year = models.CharField(max_length=4)
inspection_result = models.CharField(max_length=30,
choices=RESULT_CHOICES)
ag_rating = models.CharField(max_length=30)
inspection_date = models.DateField()
link_to_results = models.CharField(max_length=200)
def __str__(self):
return self.inspection_number`
我尝试:
YEAR_IN_SCHOOL_CHOICES = { "FR": "Freshman", "SO": "Sophomore", "JR": "Junior", "SR": "Senior", "GR": "Graduate", }
但还是没用。甚至可以由于错误而迁移
您创建了一个字符串列表,而不是一个二元组字符串列表。您应该在
'PR'
: 之后添加逗号
RESULT_CHOICES = [
('PR', 'Passed'),
('PR', 'Passed with minor Defects'),
('PR', 'Passed with major Defects'),
('FR', 'Failed due to minor Defects'),
('FR', 'Failed due to major Defects'),
('FR', 'Failed'),
]
但这仍然行不通:键应该是唯一的,否则,一旦存储在数据库中,它就无法检索确切的选择。
所以类似:
RESULT_CHOICES = [
('PR', 'Passed'),
('PRA', 'Passed with minor Defects'),
('PRI', 'Passed with major Defects'),
('FRA', 'Failed due to minor Defects'),
('FRI', 'Failed due to major Defects'),
('FR', 'Failed'),
]