django 中多 table 继承的数据库完整性问题

Database integrity issue with multi-table inheritance in django

相关型号如下:

class Event(models.Model):
    objects = InheritanceManager()

    game = models.ForeignKey(Game)
    time = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['time']

class ShipMoveEvent(Event):
    objects = InheritanceManager()

    ship = models.ForeignKey(Ship)
    space = space(null=True, blank=True)

class DepthChargeEvent(ShipMoveEvent):
    target = space()
    nearMiss = models.PositiveSmallIntegerField()
    hit = models.ForeignKey(Sub, blank=True, null=True)

我可以很好地创建 ShipMoveEvent。当我创建 DepthChargeEvent 时,保存时出现此错误:

django.db.utils.IntegrityError: NOT NULL constraint failed: sub_search_depthchargeevent.event_ptr_id

知道为什么吗?我很难过。明显跟django的multi-table继承有关系。

看来这是sqlite数据库绑定的一个bug。我切换到 postgresql 之后就没有遇到过这个问题。