diff options
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", + ), + ], + ) |
