[英]How to fix 'choices must be an iterable' error in django models?
I'm trying to migrate my app to the database, but the error does not allow me Where I should make changes? 我正在尝试将我的应用程序迁移到数据库,但错误不允许我在哪里进行更改?
I have already looked through other Decisions. 我已经查看了其他决定。 Nothing could help me 什么都没有帮助我
class Movie(models.Model):
NON_RATED = 0
RATED_G = 1
RATED_PG = 2
RATED_R = 3
RATINGS = (
(0, 'NR-not_rated'),
(1, 'G-General_Audiences'),
(2, 'PG-Parental_Guidances', 'Suggested'),
(3, 'R-Restricted')
)
rating = models.IntegerField(
choices=RATINGS,
default=0)
Choices attribute takes a list
or tuple of 2 pairs
. Choices属性采用tuple of 2 pairs
的list
或tuple of 2 pairs
。 You cannot have a third value as you have. 你不能拥有第三个价值。
class Movie(models.Model):
NON_RATED = 0
RATED_G = 1
RATED_PG = 2
RATED_R = 3
RATINGS = (
(0, 'NR-not_rated'),
(1, 'G-General_Audiences'),
(2, 'PG-Parental_Guidances', 'Suggested'), # you should remove Suggested here.
(3, 'R-Restricted')
)
rating = models.IntegerField(
choices=RATINGS,
default=0)
If you want another one you can try (2, ('PG-Parental_Guidances', 'Suggested'))
but this will also give an error in some default values because of the internal structure. 如果你想要另一个,你可以尝试(2, ('PG-Parental_Guidances', 'Suggested'))
但由于内部结构,这也会在某些默认值中出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.