Change the type of user ID to UUID

I am using the User model from django.contrib.auth.models , the default id type (primary_key) is int, how to change it to UUID ?, for example id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

+5
source share
1 answer

Use the AbstractUser model if you need changes to 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 settings.py ,

 AUTH_USER_MODEL = 'myapp.MyUser' 
+6
source

All Articles