how to use uuid instead of id as the primary key primary in django

created at 07-16-2021 views: 3

Whenever we create any new model, an ID field is appended. By default, the data type of the ID field will be Integer.

In order to make the id field a UUID, a new field type UUIDField was added in Django 1.8+.

from django.db import models

class Event(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    details = models.TextField()
    years_ago = models.PositiveIntegerField()

>>> eobj = Event.objects.all()
>>> eobj.first().id
created at:07-16-2021
edited at: 07-16-2021: