The docs for 'How Django knows to UPDATE vs. INSERT'
do not make any mention of a potentially confusing condition,
which is that updating a PK followed by a call to .save()
will always result in an INSERT rather than an UPDATE.
While this note is present in the primary key docstring
itself, it would be worthwhile to duplicate it to this section
as a gotcha.
See also: https://stackoverflow.com/q/56212145/7954504
--
Ticket URL: <https://code.djangoproject.com/ticket/30491>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* owner: nobody => Brad
* stage: Unreviewed => Accepted
Comment:
This note is already in `topics/db/models` and `ref/models/fields`, but I
agree that we can add it in one more place.
--
Ticket URL: <https://code.djangoproject.com/ticket/30491#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30491#comment:2>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30491#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"67b6cb7723b2765cb776bd59d5603e3e63eefc2e" 67b6cb77]:
{{{
#!CommitTicketReference repository=""
revision="67b6cb7723b2765cb776bd59d5603e3e63eefc2e"
Fixed #30491 -- Clarified when save() on object with pk executes INSERT.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30491#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"0f0d1cd7722238158011c7717d410fae37513ceb" 0f0d1cd]:
{{{
#!CommitTicketReference repository=""
revision="0f0d1cd7722238158011c7717d410fae37513ceb"
[2.2.x] Fixed #30491 -- Clarified when save() on object with pk executes
INSERT.
Backport of 67b6cb7723b2765cb776bd59d5603e3e63eefc2e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30491#comment:5>