[Answered ]-AssertionError: You cannot call `.save()` on a serializer with invalid data

1👍

It clearly shows that your serializer data validation failed. That is,

serializer.is_valid()

This returned false. And even after that you are saving serializer object which results in this error.

Ideally it should be like :

if serializer.is_valid()
    serializer.save()

Or much cleaner version to raise exception:

if serializer.is_valid(raise_exception=True):
    serializer.save()

You need to check why this serializer object is not valid. And then save the data if serializer.is_valid() returns True.

Leave a comment