summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-10-18 15:03:50 +0200
committerGitHub <noreply@github.com>2025-10-18 15:03:50 +0200
commit0c487aa3a7b2417481bf48c1e5355c855873e210 (patch)
tree33b92a3bdf11f66d0f67fe4b4338084c7028c709 /tests/contenttypes_tests
parentb1e0262c9f9d11eae6230b51c5aa5d71122d5f05 (diff)
Fixed #21961 -- Added support for database-level delete options for ForeignKey.
Thanks Simon Charette for pair programming. Co-authored-by: Nick Stefan <NickStefan12@gmail.com> Co-authored-by: Akash Kumar Sen <71623442+Akash-Kumar-Sen@users.noreply.github.com> Co-authored-by: Simon Charette <charette.s@gmail.com>
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)