How to convert a char field to uuid field in django models

I have a django model, where I am storing uuid kind of strings in a character field of max length 255, I want to convert this field to uuid field, how can this be done in django.

You can write this code in your models.py file.

import uuid

replace models.CharField with models.UUIDField. Overall code is:

id = models.UUIDField(
        default=uuid.uuid4,
        editable=False
    )

Then run makemigrations and migrate

Back to Top