mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #14217 -- Added validation for field name collision when using model inheritance.
This commit is contained in:
@@ -436,6 +436,25 @@ class FieldNamesTests(IsolatedModelsTestCase):
|
||||
|
||||
class ShadowingFieldsTests(IsolatedModelsTestCase):
|
||||
|
||||
def test_field_name_clash_with_child_accessor(self):
|
||||
class Parent(models.Model):
|
||||
pass
|
||||
|
||||
class Child(Parent):
|
||||
child = models.CharField(max_length=100)
|
||||
|
||||
errors = Child.check()
|
||||
expected = [
|
||||
Error(
|
||||
"The field 'child' clashes with the field "
|
||||
"'child' from model 'invalid_models_tests.parent'.",
|
||||
hint=None,
|
||||
obj=Child._meta.get_field('child'),
|
||||
id='models.E006',
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected)
|
||||
|
||||
def test_multiinheritance_clash(self):
|
||||
class Mother(models.Model):
|
||||
clash = models.IntegerField()
|
||||
|
||||
Reference in New Issue
Block a user