How to remove all relations from manytomany?

First, you'll need to clear the relationship(s) by using .clear() or .remove(), whichever suits your needs better according to the docs.

After that, you'll need to delete the object(s) by using the [YourModel].delete() method.


If you need to delete only the relationship for all instance between 2 models then you can do that by accessing the Manager of the relationship table. The m2m relationship table can be accessed via MyModel.relations.through so for deleting the relationships it becomes easy:

MyModel.relations.through.objects.all().delete()

reference:

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.through

Tags:

Django