From 0fa339ce71bae6f9cebe341876f6aa41840ca2ff Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:27:51 +0200 Subject: [6.0.x] Fixed #36611, Refs #36580 -- Added system check for multicolumn ForeignObject in Meta.indexes/constraints/unique_together. ForeignObjects with multiple `from_fields` are not supported in these options. Co-authored-by: Jacob Walls Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Backport of 5b51e6f759f2ba993219347435149173c756c478 from main. --- django/db/models/base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'django') diff --git a/django/db/models/base.py b/django/db/models/base.py index 36b16c1132..d1321d6540 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -2220,6 +2220,20 @@ class Model(AltersData, metaclass=ModelBase): id="models.E048", ) ) + elif ( + isinstance(field.remote_field, ForeignObjectRel) + and field not in cls._meta.local_concrete_fields + and len(field.from_fields) > 1 + ): + errors.append( + checks.Error( + f"{option!r} refers to a ForeignObject {field_name!r} with " + "multiple 'from_fields', which is not supported for that " + "option.", + obj=cls, + id="models.E049", + ) + ) elif field not in cls._meta.local_fields: errors.append( checks.Error( -- cgit v1.3