McKay McKay - 2 months ago 6x
Python Question

How do I make a primary key without auto-increment?

I've been trying to create a model that has a primary key, but I don't want that primary key to auto increment.

I know I can specify the value each time, but I want the field to be required that I specify it (hopefully enforced by the database and django), and fail fast if I forget.

It seemed logical that I would be able to say

on my field, but that isn't supported by the field :(


Just create id field with primary_key=True explicitly in your model:

class SomeModel(models.Model):
    id = models.IntegerField(primary_key=True)

That way it won't be auto-incremented, but it will still be an primary key.