Browse Source

Added test for Model._check_column_name_clashes().

Hasan Ramezani 6 years ago
parent
commit
ec16588c27
1 changed files with 15 additions and 0 deletions
  1. 15 0
      tests/invalid_models_tests/test_models.py

+ 15 - 0
tests/invalid_models_tests/test_models.py

@@ -421,6 +421,21 @@ class FieldNamesTests(SimpleTestCase):
             )
         ])
 
+    def test_db_column_clash(self):
+        class Model(models.Model):
+            foo = models.IntegerField()
+            bar = models.IntegerField(db_column='foo')
+
+        self.assertEqual(Model.check(), [
+            Error(
+                "Field 'bar' has column name 'foo' that is used by "
+                "another field.",
+                hint="Specify a 'db_column' for the field.",
+                obj=Model,
+                id='models.E007',
+            )
+        ])
+
 
 @isolate_apps('invalid_models_tests')
 class ShadowingFieldsTests(SimpleTestCase):