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"
This commit is contained in:
Antoine Lorence 2017-07-22 12:46:36 +02:00
parent fa2ebaec13
commit f5e173e1a2
2 changed files with 2 additions and 1 deletions

View file

@ -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',

View file

@ -40,6 +40,7 @@ class SearchEntry(models.Model):
content_type = models.ForeignKey(
ContentType,
on_delete = models.CASCADE,
)
object_id = models.TextField()