Django Automatic Primary Key Fields

By: Dusty Arlia
Published on Saturday, March 15, 2014, 02:14 PM
Last Updated on Tuesday, July 07, 2015 at 10:14 PM
Total Updates: 2

Django gives each model this default field:

id = models.AutoField(primary_key=True)

This is an auto-incrementing primary key.

If you’d like a custom primary key, specify primary_key=True on the field. 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).

Comments:

Ad:

Ad: