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
不考虑业务场景,一味的争执技术的高下,都是耍流氓。
原文地址:https://www.cnblogs.com/leoych/p/14959610.html