#33271: Bulk delete does not delete related objects
-----------------------------------------+------------------------
Reporter: Lukas Klement | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Calling Model.objects.delete() causes integrity errors with ForeignKey and
ManyToMany related objects, despite specifying on_delete=models.CASCADE
for the ForeignKey.
Here's the models:
{{{
FirstModel(models.Model):
many = models.ManyToManyField('app.SecondModel',
related_name='order_diets', blank=True)
ThirdModel(models.Model):
first = models.ForeignKey(FirstModel, on_delete=models.CASCADE,
related_name='related)
SecondModel(models.Model):
pass
}}}
Calling the bulk delete:
{{{
existing = FirstModel.objects.filter(...)
existing.delete()
}}}
... causes the following error:
{{{
IntegrityError at /mypath/.../action/
update or delete on table "..." violates foreign key constraint
"app_first_model_many_many_id_3a17178e_fk_app_first_model_id" on table
"app_first_model_many"
DETAIL: Key (id)=(123456789) is still referenced from table
"app_first_model_many".
}}}
This issue seems to have been reported previously:
https://code.djangoproject.com/ticket/31600
Django version: 3.2.8
--
Ticket URL: <https://code.djangoproject.com/ticket/33271>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.4f1cfb75737c3d01253973f157de2281%40djangoproject.com.