I need a table without a primary key (in Django it was created automatically). So my question is: Can I create a model without an ID/primary key?
I'm using Django 1.7.
Usually, Django automatically adds an integer id field to every model, this acts as an auto-incrementing primary key for every object of the model.
By default, Django adds an id field to each model, which is used as the primary key for that model.
pk is the attribute that contains the value of the primary key for the model. id is the name of the field created as a primary key by default if none is explicitly specified.
You can create a model without an auto-incrementing key, but you cannot create one without a primary key.
From the Django Documentation:
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).
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