以下是相关模型:
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。当我去创建深度充电事件时,我在保存时收到此错误:
django.db.utils.IntegrityError: NOT NULL constraint failed: sub_search_depthchargeevent.event_ptr_id
知道为什么吗?我被难住了。这显然与 django 的多表继承有关。
这似乎是 sqlite 数据库绑定中的一个错误。我切换到 postgresql,从那以后就没有遇到过这个问题。