Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the type of User ID to UUID

Tags:

python

django

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

like image 756
Yuwen Yan Avatar asked Aug 31 '15 12:08

Yuwen Yan


1 Answers

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'
like image 90
Aswin Murugesh Avatar answered Oct 13 '22 18:10

Aswin Murugesh