我有一个模特:
class Project(models.Model):
project_id = models.CharField(max_length=200)
project_name = models.CharField(max_length=200)
description = models.CharField(max_length=20)
PROJECT_TYPE_CHOICES = (
('E-Commerce','E-Commerce'),
('Business','Business'),
)
APPLICATION_TYPE_CHOICES = (
('Android','Android'),
('iOS','iOS'),
('Windows','Windows'),
)
project_type = models.CharField(max_length=2, choices=PROJECT_TYPE_CHOICES,
default='E-Commerce')
application_type = models.CharField(max_length=3,
choices=APPLICATION_TYPE_CHOICES, default='Windows')
def __str__(self):
return self.project_name
当我做的时候,它的工作正常。但是在迁移的同时显示错误
django.db.utils.OperationalError: (1067, "Invalid default value for
'application
_type'")
答案 0 :(得分:2)
您的application_type
字段只有3个字符的大小,但您的默认(和其他值)超出了该限制。只需将其扩展为7个字符。 project_type
字段也是如此。您需要重新创建迁移。
project_type = models.CharField(max_length=2, choices=PROJECT_TYPE_CHOICES, default='E-Commerce')
application_type = models.CharField(max_length=3, choices=APPLICATION_TYPE_CHOICES, default='Windows')
现在我看一下,我认为你对max_length
所指的内容感到困惑。它是字符值的大小,而不是可能的选项数。