Feature Request: set default model primary key to UUID or something else for entire project

5 views
Skip to first unread message

Brian Carter

unread,
Jun 28, 2019, 1:05:41 PM6/28/19
to Django users
I am aware that I can specify any model's primary key by adding that kwarg to a field within the model. I currently do this with most my models, using UUIDField as the primary key:

class MyModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # Insert rest of fields here

I like UUID for my PK's a lot (I don't want someone able to simply guess at what my PK's are because they are just auto-incrementing integers - if there is a 74 then its obvious that there is 1-73 as IDs), and it is very handy to be able to specify this and overwrite the default AutoField within each model.

What I would like is for someway to configure this behavior globally in the settings.py project settings. If I desire to change it globally like this, I think it reasonable to have a finite list of viable replacements, such as UUIDField, to replace it, as the main constraint is uniqueness within the DB Table for PK's.

Setting this would make it so I do not have to specify an id field for every model to use the UUID PK that I want to use, which would be convenient for me. I would also like it to affect the Join Tables created by Many to Many Fields
Reply all
Reply to author
Forward
0 new messages