I have a Django model(Feature
) sub-classing MPTTModel. As best practice for MPTT model for foreign key is to keep on_delete=PROTECT
, struggling to delete all MPTT entries at once, using
Feature.objects.all().delete()
I get following error
django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'Feature' because they are referenced through a protected foreign key: 'Feature.parent'"...
I can either first delete all child nodes, and then root nodes. But this does not seem efficient to me. Is there any better option ?