Opened 12 years ago
Closed 12 years ago
#19956 closed Uncategorized (invalid)
Manual PrimaryKey isn't updated after save, create
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.5 |
Severity: | Normal | Keywords: | primary_key |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The regular auto id field is updated after the object is saved to the database. This doesn't happen when using manual primary keys:
class A(models.Model): pass class B(models.Model): id = models.IntegerField(primary_key=True) A.objects.create().pk # 1 B.objects.create().pk # None
The pk value is only updated for auto fields:
https://github.com/django/django/blob/master/django/db/models/base.py#L649
Note:
See TracTickets
for help on using tickets.