首页 > 技术文章 > djandgo model id

littlefire 2014-04-05 14:08 原文

django 关于model id:

Automatic primary key fields
By default, Django gives each model the following field:

id = models.AutoField(primary_key=True)
This is an auto-incrementing primary key.

If you’d like to specify a custom primary key, just 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.

  来源:http://django-chinese-docs.readthedocs.org/en/latest/topics/db/models.html#automatic-primary-key-fields

推荐阅读