[Django]-UUID Is not JSON Serializable (dumpdata)

0👍

In my models.py:

import uuid

In my model:

class MyUser(AbstractUser):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

and to solve this problem, I use this function write in MyUser:

def user_id(self):
    return self.id.__str__()

As the TypeError try you that type UUID is not JSON serializable,

so you should use string instead.

Hope it will help you.

👤Henry

Leave a comment