In Django, I have a model:
class HmmInsectValue(models.Model):
hmm = models.ForeignKey('HmmResult', on_delete=models.CASCADE)
...
on a PostgreSQL database (9.3.2) this produces a constraint:
FOREIGN KEY (hmm_id) REFERENCES devdash_hmmresult(id) DEFERRABLE INITIALLY DEFERRED
while what I really want is:
FOREIGN KEY (hmm_id) REFERENCES devdash_hmmresult(id) ON DELETE CASCADE
This breaks my code because when I try to delete an HmmResult
entry it complains that it's is still referenced from HmmInsectValue
. If I replace it manually with the line above it all works fine.
Any idea why this is happening?