Django by default makes a primary key field on each model named “id“, with a type of AutoField. On my models, I’m overriding this to use a custom UUIDField as the primary key by using the “primary_key” attribute. I would also like the User model in django.contrib.auth to have a UUIDField as the primary key, but this doesn’t seem to be possible without changing the User model source code.
Is there any recommended way to approach this problem?
Correct. Unless you are willing to change (or replace)
Userthere isn’t a way.One (tenuous, hackish) way to do this would be to attach an
UserProfilefor eachUserinstance. EachUsershould have exactly oneUserProfile. You can then add yourUUIDFieldto the profile. You will still have to do custom querying to translate fromUUIDFieldtoid.If you don’t like the name
UserProfileyou can rename it suitably. The key is that you have a one-to-one relationship toUser.