Django: You are trying to add a non-nullable field 'name' to mainnav without a default; we can't do that (the database needs something to populate existing rows).

错误原因:

语句中缺少默认值

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

 

posted @ 2021-07-01 16:55  胸怀丶若谷  阅读(216)  评论(0)    收藏  举报