其他分享
首页 > 其他分享> > Django: You are trying to add a non-nullable field 'name' to mainnav without a default; we

Django: You are trying to add a non-nullable field 'name' to mainnav without a default; we

作者:互联网

错误原因:

语句中缺少默认值

class Main(models.Model):
    img = models.CharField(max_length=255)
    name = models.CharField(max_length=64)
    trackid = models.IntegerField(default=1)

    class Meta:
        abstract = True

解决方案:

在语句中添加任意的默认值,之后再执行ORM迁移指令:

class Main(models.Model):
    img = models.CharField(max_length=255, default='1')
    name = models.CharField(max_length=64, default='1')
    trackid = models.IntegerField(default=1)

    class Meta:
        abstract = True

 

标签:do,non,models,max,existing,default,length,CharField,class
来源: https://www.cnblogs.com/leoych/p/14959610.html