1
0
mirror of https://github.com/django/django.git synced 2025-03-25 08:40:45 +00:00

[5.1.x] Fixed #36077 -- Corrected docs on pk value where Model.save() executes an UPDATE.

The empty string is no longer special-cased since
c2ba59fc1da5287d6286e2c2aca4083d5bafe056.

Backport of d66137b39b1503ca3d4d4fac687251adbc845068 from main.
This commit is contained in:
Jacob Walls 2025-01-09 09:50:30 -05:00 committed by Sarah Boyce
parent 8d81c4730f
commit b325864686

View File

@ -552,9 +552,8 @@ object's primary key attribute does **not** define a
:attr:`~django.db.models.Field.default` or :attr:`~django.db.models.Field.default` or
:attr:`~django.db.models.Field.db_default`, Django follows this algorithm: :attr:`~django.db.models.Field.db_default`, Django follows this algorithm:
* If the object's primary key attribute is set to a value that evaluates to * If the object's primary key attribute is set to anything except ``None``,
``True`` (i.e., a value other than ``None`` or the empty string), Django Django executes an ``UPDATE``.
executes an ``UPDATE``.
* If the object's primary key attribute is *not* set or if the ``UPDATE`` * If the object's primary key attribute is *not* set or if the ``UPDATE``
didn't update anything (e.g. if primary key is set to a value that doesn't didn't update anything (e.g. if primary key is set to a value that doesn't
exist in the database), Django executes an ``INSERT``. exist in the database), Django executes an ``INSERT``.