Use UUID as primary key

Whenever we create any new model, there is an ID field attached to it. The ID field’s data type will be Integer by default.
Snippet code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import uuid
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()

>>> eventobject = Event.objects.all()
>>> eventobject.first().id
'3cd2b4b0c36f43488a93b3bb72029f46'
The end