[Fixed]-Django difference between clear() and delete()


user.groups.all().delete() will delete the related group objects, while user.groups.clear() will only disassociate the relation:


Removes all objects from the related object set:
Note this doesn’t delete the related objects – it just disassociates them.

Note that deleting the related objects may have the side effect that other users belonging to the same group may also be deleted (by cascade), depending on the ForeignKey rules specified by on_delete.




This unlinks the groups from the user, but does not affect the groups themselves.


This deletes the actual groups. You probably don’t want to do this because there might be other users that belong to those groups as well.

Leave a comment