summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/test_checks.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/test_checks.py b/tests/contenttypes_tests/test_checks.py
index c33920f6b7..5c88b71777 100644
--- a/tests/contenttypes_tests/test_checks.py
+++ b/tests/contenttypes_tests/test_checks.py
@@ -80,6 +80,27 @@ class GenericForeignKeyTests(SimpleTestCase):
],
)
+ def test_content_type_db_on_delete(self):
+ class Model(models.Model):
+ content_type = models.ForeignKey(ContentType, models.DB_CASCADE)
+ object_id = models.PositiveIntegerField()
+ content_object = GenericForeignKey("content_type", "object_id")
+
+ field = Model._meta.get_field("content_object")
+
+ self.assertEqual(
+ field.check(),
+ [
+ checks.Error(
+ "'Model.content_type' cannot use the database-level on_delete "
+ "variant.",
+ hint="Change the on_delete rule to the non-database variant.",
+ obj=field,
+ id="contenttypes.E006",
+ )
+ ],
+ )
+
def test_missing_object_id_field(self):
class TaggedItem(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE)