(fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples
I created this model below and I was working fine for almost the whole week. Closed the server and restarted it again and it threw me the (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples error. Used django documentation exactly, still no solution.
`class Inspection(models.Model):
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`
I tried to:
YEAR_IN_SCHOOL_CHOICES = { "FR": "Freshman", "SO": "Sophomore", "JR": "Junior", "SR": "Senior", "GR": "Graduate", }
but still didn't work. Can even migrate due to the error
Used django documentation exactly, still no solution.
You made a list of strings, not a list of 2-tuples, of strings. You should add a comma after 'PR'
. There is a difference between 'foo' 'bar'
and 'foo', 'bar'
. For the former, you use string literal concatenation [python-doc]:
RESULT_CHOICES = [
# 🖟 comma (,)
('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'),
]
But this will still not work: the keys should be unique, otherwise, once stored in the database, it can not retrieve the exact choice.
So something like:
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'),
]