diff --git a/django/db/models/base.py b/django/db/models/base.py index e68baf4e57..cd300e47bc 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1088,6 +1088,7 @@ class Model(AltersData, metaclass=ModelBase): if ( not raw and not force_insert + and not force_update and self._state.adding and ( (meta.pk.default and meta.pk.default is not NOT_PROVIDED) diff --git a/tests/basic/tests.py b/tests/basic/tests.py index bda59d82fa..38fb9ca200 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -186,6 +186,12 @@ class ModelInstanceCreationTests(TestCase): with self.assertNumQueries(1): PrimaryKeyWithDefault().save() + def test_save_primary_with_default_force_update(self): + # An UPDATE attempt is made if explicitly requested. + obj = PrimaryKeyWithDefault.objects.create() + with self.assertNumQueries(1): + PrimaryKeyWithDefault(uuid=obj.pk).save(force_update=True) + def test_save_primary_with_db_default(self): # An UPDATE attempt is skipped when a primary key has db_default. with self.assertNumQueries(1):