[Django]-Change the type of User ID to UUID

39👍

Use AbstractUser model if you need changes in the default user model.

import uuid
from django.db import models
from django.contrib.auth.models import AbstractUser

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

Then in your settings.py,

AUTH_USER_MODEL = 'myapp.MyUser'

0👍

If you had already executed any migrations before making the UUID change, it is crucial to delete the tables and recreate the migrations.

👤Ayman

Leave a comment