Is there a maximum value as to how high pk values for a model can get? For example, for something like an activity feed model, the pk's can get really large.
Ex, "Kyle liked this post", "Alex commented on this post" etc..As you can see, for every action, an activity feed object is created. Is there some sort of maximum threshold that will be reached? I've done some research but haven't found a concise answer. If there is some limit, how can one overcome this?
I currently use PostgreSQL as my database.
Every table should have a primary key, so every model should have a primary key field. However, you do not have to do this manually if you do not want. By default, Django adds an id field to each model, which is used as the primary key for that model.
primary_key: If True , sets the current field as the primary key for the model (A primary key is a special database column designated to uniquely identify all the different table records). If no field is specified as the primary key, Django will automatically add a field for this purpose.
Do Django models support multiple-column primary keys? ¶ No. Only single-column primary keys are supported.
If you'd like to specify a custom primary key, specify primary_key=True on one of your fields. If Django sees you've explicitly set Field.primary_key , it won't add the automatic id column. Each model requires exactly one field to have primary_key=True (either explicitly declared or automatically added).
Django's auto-incrementing IDs are AutoFields, a subclass of IntegerField. It will generate the primary keys as PostgreSQL integer
, which are signed 32-bit integers with a maximum value of 2147483647, a little over 2 billion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With