From f5e173e1a2ce6101b9d6fd566f41e13c7d752c8c Mon Sep 17 00:00:00 2001 From: Antoine Lorence Date: Sat, 22 Jul 2017 12:46:36 +0200 Subject: [PATCH] Set on_delete=CASCADE for ForeignKey model fields This is the default behavior, but since on_delete argument will be required in Django 2.0, and a warning is thrown in recent versions of Django when the attribute is missing, it's better to set it in code. In addition, "explicit is better than implicit" --- watson/migrations/0001_initial.py | 2 +- watson/models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/watson/migrations/0001_initial.py b/watson/migrations/0001_initial.py index 6b7af3b..8eab3dc 100644 --- a/watson/migrations/0001_initial.py +++ b/watson/migrations/0001_initial.py @@ -32,7 +32,7 @@ class Migration(migrations.Migration): ('content', models.TextField(blank=True)), ('url', models.CharField(max_length=1000, blank=True)), ('meta_encoded', models.TextField()), - ('content_type', models.ForeignKey(to='contenttypes.ContentType')), + ('content_type', models.ForeignKey(to='contenttypes.ContentType', on_delete=models.CASCADE)), ], options={ 'verbose_name_plural': 'search entries', diff --git a/watson/models.py b/watson/models.py index fb3d382..c3cf44f 100644 --- a/watson/models.py +++ b/watson/models.py @@ -40,6 +40,7 @@ class SearchEntry(models.Model): content_type = models.ForeignKey( ContentType, + on_delete = models.CASCADE, ) object_id = models.TextField()