summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2018-05-03 11:38:29 +0430
committerCarlton Gibson <carlton.gibson@noumenal.es>2018-05-03 09:08:29 +0200
commit816b8d9518c41f034dcbacfd1f1826f2366975e5 (patch)
tree997a10e0626c8aa06631a7056ef8ff5d56e33edc /tests/invalid_models_tests
parent98019df855fb8fb93e4e9505afeedcad29da3125 (diff)
Fixed #29358 -- Added a system check to prohibit models with more than one primary_key field.
Diffstat (limited to 'tests/invalid_models_tests')
-rw-r--r--tests/invalid_models_tests/test_models.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index cfd1a7c465..2066d4ebae 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -717,6 +717,19 @@ class OtherModelTests(SimpleTestCase):
)
])
+ def test_single_primary_key(self):
+ class Model(models.Model):
+ foo = models.IntegerField(primary_key=True)
+ bar = models.IntegerField(primary_key=True)
+
+ self.assertEqual(Model.check(), [
+ Error(
+ "Model can not contain more than one 'primary_key' field.",
+ obj=Model,
+ id='models.E026',
+ )
+ ])
+
@override_settings(TEST_SWAPPED_MODEL_BAD_VALUE='not-a-model')
def test_swappable_missing_app_name(self):
class Model(models.Model):