Skip to content

Commit

Permalink
Refs #29260 -- Mentionned the behavior change of save for pk defaults…
Browse files Browse the repository at this point in the history
… in the release notes.
  • Loading branch information
charettes committed Dec 12, 2019
1 parent bc283ce commit 8f87f42
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/releases/3.0.txt
Expand Up @@ -372,6 +372,22 @@ Tests
Backwards incompatible changes in 3.0
=====================================

``Model.save`` on models when providing a default for the primary key
---------------------------------------------------------------------

Before Django 3.0 ``Model().save()`` would always attempt to find a row
when a default value for the primary key was provided and proceed to perform
either an ``INSERT`` or an ``UPDATE`` based on whether or not the row exists.

Since Django 3.0 a single ``INSERT`` query is attempted which makes calling
``Model().save()`` while providing a default primary key value equivalent to
passing ``force_insert=True`` to ``save`. That makes attempts to use a new
``Model`` instance to update an existing row result in an ``IntegrityError``.

In order to update an existing model for a specific primary key value use the
``get_or_update`` method defined on the model manager instead.


Database backend API
--------------------

Expand Down

0 comments on commit 8f87f42

Please sign in to comment.