diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_fields/test_foreignkey.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/model_fields/test_foreignkey.py b/tests/model_fields/test_foreignkey.py index 51e76c4052..d30cca9b5c 100644 --- a/tests/model_fields/test_foreignkey.py +++ b/tests/model_fields/test_foreignkey.py @@ -2,6 +2,7 @@ from decimal import Decimal from django.apps import apps from django.core import checks +from django.core.exceptions import FieldError from django.db import models from django.test import TestCase, skipIfDBFeature from django.test.utils import isolate_apps @@ -128,3 +129,21 @@ class ForeignKeyTests(TestCase): with self.assertRaisesMessage(ValueError, 'Cannot resolve output_field'): Foo._meta.get_field('bar').get_col('alias') + + @isolate_apps('model_fields') + def test_non_local_to_field(self): + class Parent(models.Model): + key = models.IntegerField(unique=True) + + class Child(Parent): + pass + + class Related(models.Model): + child = models.ForeignKey(Child, on_delete=models.CASCADE, to_field='key') + + msg = ( + "'model_fields.Related.child' refers to field 'key' which is not " + "local to model 'model_fields.Child'." + ) + with self.assertRaisesMessage(FieldError, msg): + Related._meta.get_field('child').related_fields |
