mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #35992, Fixed #35997 -- Added system check for CompositePrimaryKeys in Meta.indexes/constraints/unique_together.
CompositePrimaryKeys are not supported in any of these options.
This commit is contained in:
committed by
Sarah Boyce
parent
322e49ba30
commit
2249370c86
@@ -2288,6 +2288,16 @@ class Model(AltersData, metaclass=ModelBase):
|
||||
id="models.E013",
|
||||
)
|
||||
)
|
||||
elif isinstance(field, models.CompositePrimaryKey):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
f"{option!r} refers to a CompositePrimaryKey "
|
||||
f"{field_name!r}, but CompositePrimaryKeys are not "
|
||||
f"permitted in {option!r}.",
|
||||
obj=cls,
|
||||
id="models.E048",
|
||||
)
|
||||
)
|
||||
elif field not in cls._meta.local_fields:
|
||||
errors.append(
|
||||
checks.Error(
|
||||
|
||||
@@ -93,11 +93,13 @@ class BaseConstraint:
|
||||
return []
|
||||
|
||||
def _check_references(self, model, references):
|
||||
from django.db.models.fields.composite import CompositePrimaryKey
|
||||
|
||||
errors = []
|
||||
fields = set()
|
||||
for field_name, *lookups in references:
|
||||
# pk is an alias that won't be found by opts.get_field.
|
||||
if field_name != "pk":
|
||||
# pk is an alias that won't be found by opts.get_field().
|
||||
if field_name != "pk" or isinstance(model._meta.pk, CompositePrimaryKey):
|
||||
fields.add(field_name)
|
||||
if not lookups:
|
||||
# If it has no lookups it cannot result in a JOIN.
|
||||
|
||||
Reference in New Issue
Block a user