diff options
| author | Bendeguz Csirmaz <csirmazbendeguz@gmail.com> | 2025-01-13 19:33:47 +0800 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-13 14:21:41 +0100 |
| commit | d83fb782d33aa7aaa1b2c995c648a59eddb46047 (patch) | |
| tree | a825df76c6c0a0e405c019719b4f53ea58ae1f24 /tests | |
| parent | bf7b17d16d3978b2e1cee4a0f7ce8840bd1a8dc4 (diff) | |
Fixed #36092 -- Disallowed non-local fields in composite primary keys.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/composite_pk/test_checks.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/composite_pk/test_checks.py b/tests/composite_pk/test_checks.py index c803d521cc..c33f2ee2eb 100644 --- a/tests/composite_pk/test_checks.py +++ b/tests/composite_pk/test_checks.py @@ -247,3 +247,24 @@ class CompositePKChecksTests(TestCase): ), ], ) + + def test_composite_pk_cannot_include_non_local_field(self): + class Foo(models.Model): + a = models.SmallIntegerField() + + class Bar(Foo): + pk = models.CompositePrimaryKey("a", "b") + b = models.SmallIntegerField() + + self.assertEqual(Foo.check(databases=self.databases), []) + self.assertEqual( + Bar.check(databases=self.databases), + [ + checks.Error( + "'a' cannot be included in the composite primary key.", + hint="'a' field is not a local field.", + obj=Bar, + id="models.E042", + ), + ], + ) |
