Opened 12 years ago

Closed 12 years ago

#19956 closed Uncategorized (invalid)

Manual PrimaryKey isn't updated after save, create

Reported by: grzesiof@… 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

Change History (1)

comment:1 by grzesiof@…, 12 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top