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.
* status: new => closed
* resolution: => duplicate
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Bug
Comment:
Thanks for the report, however I cannot reproduce this with provided
models. Please reopen the original ticket #31600 if you can debug your
issue and provide a sample project to reproduce it.
Duplicate of #31600.
--
Ticket URL: <https://code.djangoproject.com/ticket/33271#comment:1>