【发布时间】:2022-01-01 23:35:04
【问题描述】:
我看不出这有什么问题,
class Agenda(models.Model):
...
class AgendaResource(PolymorphicModel):
agenda = models.ForeignKey(
Agenda, related_name="resources", on_delete=models.CASCADE
)
comment = models.TextField(null=True)
class PreemptiveMeasureResource(AgendaResource):
resource = models.ForeignKey(
PreemptiveMeasure, on_delete=models.SET_NULL, null=True
)
...
当我尝试删除议程时,即Agenda.objects.get(pk=2).delete() 我遇到了这个问题:
update or delete on table "school_health_agendaresource" violates foreign key constraint "school_health_preemp_agendaresource_ptr_i_222e2e2c_fk_school_he" on table "school_health_preemptivemeasureresource"
DETAIL: Key (id)=(2) is still referenced from table "school_health_preemptivemeasureresource"
什么是我不明白的?我猜这与继承有关?
【问题讨论】:
标签: django postgresql django-orm