[英]Django Migration Error: ERRORS: 'choices' must be an iterable (e.g., a list or tuple)
[英]How to fix 'choices must be an iterable' error in django models?
我正在尝试将我的应用程序迁移到数据库,但错误不允许我在哪里进行更改?
我已经查看了其他决定。 什么都没有帮助我
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属性采用tuple of 2 pairs
的list
或tuple of 2 pairs
。 你不能拥有第三个价值。
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)
如果你想要另一个,你可以尝试(2, ('PG-Parental_Guidances', 'Suggested'))
但由于内部结构,这也会在某些默认值中出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.