summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-01-22 22:21:09 -0500
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-01-28 11:20:51 +0100
commit791ed4fd97a1a58401cd911dd69a32808fb86f79 (patch)
tree418cf23fd2eb06718ed633686fa528c2bdb6c1b5 /django/db/models/sql
parent720ef7a867eab1491f5789fe39b3431a498b2b89 (diff)
[5.2.x] Fixed #36120 -- Raised FieldError when targeting a composite primary key field with QuerySet.update().
Backport of 72ff18d41cfb004ae180bdf87fd8bad93041c691 from main.
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/subqueries.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index b2810c8413..9cb971b38f 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -90,6 +90,10 @@ class UpdateQuery(Query):
not (field.auto_created and not field.concrete) or not field.concrete
)
model = field.model._meta.concrete_model
+ if field.name == "pk" and model._meta.is_composite_pk:
+ raise FieldError(
+ "Composite primary key fields must be updated individually."
+ )
if not direct or (field.is_relation and field.many_to_many):
raise FieldError(
"Cannot update model field %r (only non-relations and "