完整性错误 - 整数字段可能不为空

anc*_*evv 4 django

class Incubator(models.Model):
    name = models.CharField(max_length=30)
    category = models.CharField(max_length=30, blank=True)
    acceptanceRate = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
    funding = models.IntegerField()
    programLength = models.DecimalField(max_digits=4, decimal_places=2)
    kloutScore = models.IntegerField(blank=True, null=True)
    companies = models.ManyToManyField(Company, blank=True)

    def __unicode__(self):
        return self.name
Run Code Online (Sandbox Code Playgroud)

当我将任何整数字段留空时,我不断收到错误消息,

IntegrityError at /admin/incubators/incubator/add/
incubators_incubator.kloutScore may not be NULL
Run Code Online (Sandbox Code Playgroud)

我认为通过将blank = true和null = true,它会解决这个问题吗?

anc*_*evv 7

这是因为我已经创建了数据库后添加了"blank = true"和"null = true".我不得不删除我的数据库然后"syncdb"然后它工作.

  • 使用南:http://south.aeracode.org/,您不必删除数据库. (3认同)
  • 或者在Django 1.7中,现在有内置的迁移 (3认同)