From 591f636a6dcdd8e750159cc7d194b8e7549cb5fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Wed, 2 Oct 2019 12:05:12 +0200
Subject: [PATCH 1/4] misc: add explicit on_delete on all FKs (#36608)

RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0.
Set it to models.CASCADE on models and in existing migrations if you want to maintain the
current default behavior.
See https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.on_delete
---
 passerelle/apps/astregs/models.py                  |  2 +-
 .../apps/csvdatasource/migrations/0007_query.py    |  2 +-
 passerelle/apps/csvdatasource/models.py            |  4 ++--
 passerelle/apps/family/migrations/0001_initial.py  | 14 +++++++-------
 .../family/migrations/0003_auto_20161021_0333.py   |  2 +-
 passerelle/apps/family/models.py                   | 12 ++++++------
 passerelle/apps/gesbac/models.py                   |  2 +-
 .../migrations/0002_jsondata_datastore.py          |  2 +-
 passerelle/apps/jsondatastore/models.py            |  2 +-
 passerelle/apps/mdel/migrations/0001_initial.py    |  2 +-
 passerelle/apps/mdel/models.py                     |  2 +-
 passerelle/apps/phonecalls/models.py               |  2 +-
 passerelle/apps/solis/migrations/0001_initial.py   |  2 +-
 passerelle/apps/solis/models.py                    |  4 ++--
 passerelle/apps/sp_fr/models.py                    |  6 ++++--
 passerelle/base/migrations/0001_initial.py         |  4 ++--
 passerelle/base/migrations/0006_resourcestatus.py  |  2 +-
 passerelle/base/models.py                          | 12 ++++++------
 .../contrib/agoraplus/migrations/0001_initial.py   |  2 +-
 .../agoraplus/migrations/0002_agoraplussas.py      |  2 +-
 passerelle/contrib/agoraplus/models.py             |  4 ++--
 .../contrib/dpark/migrations/0001_initial.py       |  2 +-
 passerelle/contrib/dpark/models.py                 |  2 +-
 passerelle/contrib/planitech/models.py             |  2 +-
 .../teamnet_axel/migrations/0001_initial.py        |  2 +-
 .../teamnet_axel/migrations/0006_rename_model_2.py |  2 +-
 passerelle/contrib/teamnet_axel/models.py          |  2 +-
 27 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/passerelle/apps/astregs/models.py b/passerelle/apps/astregs/models.py
index f71ea080..742d2eca 100644
--- a/passerelle/apps/astregs/models.py
+++ b/passerelle/apps/astregs/models.py
@@ -645,7 +645,7 @@ class AstreGS(BaseResource):
 
 
 class Link(models.Model):
-    resource = models.ForeignKey(AstreGS)
+    resource = models.ForeignKey(AstreGS, on_delete=models.CASCADE)
     name_id = models.CharField(max_length=32)
     association_id = models.CharField(max_length=32)
     created = models.DateTimeField(auto_now_add=True)
diff --git a/passerelle/apps/csvdatasource/migrations/0007_query.py b/passerelle/apps/csvdatasource/migrations/0007_query.py
index 5f50c3e4..24493d66 100644
--- a/passerelle/apps/csvdatasource/migrations/0007_query.py
+++ b/passerelle/apps/csvdatasource/migrations/0007_query.py
@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
                 ('order', models.TextField(help_text='Columns to use for sorting rows', verbose_name='Sort Order', blank=True)),
                 ('distinct', models.TextField(help_text='Distinct columns', verbose_name='Distinct', blank=True)),
                 ('structure', models.CharField(default=b'dict', help_text='Data structure used for the response', max_length=20, verbose_name='Structure', choices=[(b'array', 'Array'), (b'dict', 'Dictionary'), (b'tuples', 'Tuples'), (b'onerow', 'Single Row'), (b'one', 'Single Value')])),
-                ('resource', models.ForeignKey(to='csvdatasource.CsvDataSource')),
+                ('resource', models.ForeignKey(to='csvdatasource.CsvDataSource', on_delete=models.CASCADE)),
             ],
             options={
                 'ordering': ['slug'],
diff --git a/passerelle/apps/csvdatasource/models.py b/passerelle/apps/csvdatasource/models.py
index 397d40c8..a7043426 100644
--- a/passerelle/apps/csvdatasource/models.py
+++ b/passerelle/apps/csvdatasource/models.py
@@ -59,7 +59,7 @@ def normalize(value):
 
 
 class Query(models.Model):
-    resource = models.ForeignKey('CsvDataSource')
+    resource = models.ForeignKey('CsvDataSource', on_delete=models.CASCADE)
     slug = models.SlugField(_('Name (slug)'))
     label = models.CharField(_('Label'), max_length=100)
     description = models.TextField(_('Description'), blank=True)
@@ -429,7 +429,7 @@ class CsvDataSource(BaseResource):
 
 
 class TableRow(models.Model):
-    resource = models.ForeignKey('CsvDataSource')
+    resource = models.ForeignKey('CsvDataSource', on_delete=models.CASCADE)
     line_number = models.IntegerField(null=False)
     data = jsonfield.JSONField(blank=True)
 
diff --git a/passerelle/apps/family/migrations/0001_initial.py b/passerelle/apps/family/migrations/0001_initial.py
index f174d791..84b3e637 100644
--- a/passerelle/apps/family/migrations/0001_initial.py
+++ b/passerelle/apps/family/migrations/0001_initial.py
@@ -68,7 +68,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('name_id', models.CharField(max_length=256)),
-                ('family', models.ForeignKey(to='family.Family')),
+                ('family', models.ForeignKey(to='family.Family', on_delete=models.CASCADE)),
             ],
         ),
         migrations.CreateModel(
@@ -100,8 +100,8 @@ class Migration(migrations.Migration):
                 ('payment_date', models.DateTimeField(null=True, verbose_name='Payment date')),
                 ('autobilling', models.BooleanField(default=False, verbose_name='Autobilling')),
                 ('payment_transaction_id', models.CharField(max_length=128, null=True, verbose_name='Payment transaction id')),
-                ('family', models.ForeignKey(to='family.Family')),
-                ('resource', models.ForeignKey(to='family.GenericFamily')),
+                ('family', models.ForeignKey(to='family.Family', on_delete=models.CASCADE)),
+                ('resource', models.ForeignKey(to='family.GenericFamily', on_delete=models.CASCADE)),
             ],
             options={
                 'ordering': ['issue_date'],
@@ -110,21 +110,21 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='familylink',
             name='resource',
-            field=models.ForeignKey(to='family.GenericFamily'),
+            field=models.ForeignKey(to='family.GenericFamily', on_delete=models.CASCADE),
         ),
         migrations.AddField(
             model_name='family',
             name='resource',
-            field=models.ForeignKey(to='family.GenericFamily'),
+            field=models.ForeignKey(to='family.GenericFamily', on_delete=models.CASCADE),
         ),
         migrations.AddField(
             model_name='child',
             name='family',
-            field=models.ForeignKey(to='family.Family'),
+            field=models.ForeignKey(to='family.Family', on_delete=models.CASCADE),
         ),
         migrations.AddField(
             model_name='adult',
             name='family',
-            field=models.ForeignKey(to='family.Family'),
+            field=models.ForeignKey(to='family.Family', on_delete=models.CASCADE),
         ),
     ]
diff --git a/passerelle/apps/family/migrations/0003_auto_20161021_0333.py b/passerelle/apps/family/migrations/0003_auto_20161021_0333.py
index 44bae536..a88902d1 100644
--- a/passerelle/apps/family/migrations/0003_auto_20161021_0333.py
+++ b/passerelle/apps/family/migrations/0003_auto_20161021_0333.py
@@ -19,6 +19,6 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='invoice',
             name='family',
-            field=models.ForeignKey(to='family.Family', null=True),
+            field=models.ForeignKey(to='family.Family', null=True, on_delete=models.CASCADE),
         ),
     ]
diff --git a/passerelle/apps/family/models.py b/passerelle/apps/family/models.py
index 77c6ea92..b39100da 100644
--- a/passerelle/apps/family/models.py
+++ b/passerelle/apps/family/models.py
@@ -377,13 +377,13 @@ class GenericFamily(BaseResource):
 
 
 class FamilyLink(models.Model):
-    resource = models.ForeignKey('GenericFamily')
+    resource = models.ForeignKey('GenericFamily', on_delete=models.CASCADE)
     name_id = models.CharField(max_length=256)
-    family = models.ForeignKey('Family')
+    family = models.ForeignKey('Family', on_delete=models.CASCADE)
 
 
 class Family(models.Model):
-    resource = models.ForeignKey('GenericFamily')
+    resource = models.ForeignKey('GenericFamily', on_delete=models.CASCADE)
     external_id = models.CharField(_('External id'),
                 max_length=16, db_index=True)
     login = models.CharField(_('Login'), max_length=64, null=True)
@@ -405,7 +405,7 @@ class Family(models.Model):
 
 
 class Person(models.Model):
-    family = models.ForeignKey('Family')
+    family = models.ForeignKey('Family', on_delete=models.CASCADE)
     external_id = models.CharField(_('Person\'s external id'), max_length=32,
                     db_index=True)
     first_name = models.CharField(_('First name'), max_length=64)
@@ -444,8 +444,8 @@ class Child(Person):
 
 
 class Invoice(models.Model):
-    resource = models.ForeignKey('GenericFamily')
-    family = models.ForeignKey('Family', null=True)
+    resource = models.ForeignKey('GenericFamily', on_delete=models.CASCADE)
+    family = models.ForeignKey('Family', null=True, on_delete=models.CASCADE)
     external_id = models.CharField(_('External id'), max_length=128, db_index=True)
     label = models.CharField(_('Label'), max_length=128, null=True)
     issue_date = models.DateField(_('Issue date'), null=True)
diff --git a/passerelle/apps/gesbac/models.py b/passerelle/apps/gesbac/models.py
index cada62ff..7520fc37 100644
--- a/passerelle/apps/gesbac/models.py
+++ b/passerelle/apps/gesbac/models.py
@@ -424,7 +424,7 @@ FORM_STATUSES = (
 
 
 class Form(models.Model):
-    resource = models.ForeignKey(Gesbac)
+    resource = models.ForeignKey(Gesbac, on_delete=models.CASCADE)
     form_id = models.CharField(max_length=64)
     creation_datetime = models.DateTimeField(auto_now_add=True)
     filename = models.CharField(max_length=128, null=True)
diff --git a/passerelle/apps/jsondatastore/migrations/0002_jsondata_datastore.py b/passerelle/apps/jsondatastore/migrations/0002_jsondata_datastore.py
index 04e44f5d..40712311 100644
--- a/passerelle/apps/jsondatastore/migrations/0002_jsondata_datastore.py
+++ b/passerelle/apps/jsondatastore/migrations/0002_jsondata_datastore.py
@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='jsondata',
             name='datastore',
-            field=models.ForeignKey(to='jsondatastore.JsonDataStore', null=True),
+            field=models.ForeignKey(to='jsondatastore.JsonDataStore', null=True, on_delete=models.CASCADE),
         ),
     ]
diff --git a/passerelle/apps/jsondatastore/models.py b/passerelle/apps/jsondatastore/models.py
index 62d60fed..2fcd3b38 100644
--- a/passerelle/apps/jsondatastore/models.py
+++ b/passerelle/apps/jsondatastore/models.py
@@ -32,7 +32,7 @@ def get_hex_uuid():
 
 
 class JsonData(models.Model):
-    datastore = models.ForeignKey('JsonDataStore', null=True)
+    datastore = models.ForeignKey('JsonDataStore', null=True, on_delete=models.CASCADE)
 
     uuid = models.CharField(_('uuid'), max_length=32,
             default=get_hex_uuid, editable=False, unique=True)
diff --git a/passerelle/apps/mdel/migrations/0001_initial.py b/passerelle/apps/mdel/migrations/0001_initial.py
index b4699ef6..9b94f7ea 100644
--- a/passerelle/apps/mdel/migrations/0001_initial.py
+++ b/passerelle/apps/mdel/migrations/0001_initial.py
@@ -38,7 +38,7 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='demand',
             name='resource',
-            field=models.ForeignKey(to='mdel.MDEL'),
+            field=models.ForeignKey(to='mdel.MDEL', on_delete=models.CASCADE),
         ),
         migrations.AlterUniqueTogether(
             name='demand',
diff --git a/passerelle/apps/mdel/models.py b/passerelle/apps/mdel/models.py
index 9650823b..c0f2e5ee 100644
--- a/passerelle/apps/mdel/models.py
+++ b/passerelle/apps/mdel/models.py
@@ -154,7 +154,7 @@ class MDEL(BaseResource):
 class Demand(models.Model):
     created_at = models.DateTimeField(auto_now_add=True)
     updated_at = models.DateTimeField(auto_now=True)
-    resource = models.ForeignKey(MDEL)
+    resource = models.ForeignKey(MDEL, on_delete=models.CASCADE)
     num = models.CharField(
         max_length=64, null=False, primary_key=True, unique=True)
     flow_type = models.CharField(max_length=32, null=False)
diff --git a/passerelle/apps/phonecalls/models.py b/passerelle/apps/phonecalls/models.py
index 80658a00..82c5acb1 100644
--- a/passerelle/apps/phonecalls/models.py
+++ b/passerelle/apps/phonecalls/models.py
@@ -116,7 +116,7 @@ class PhoneCalls(BaseResource):
 
 
 class Call(models.Model):
-    resource = models.ForeignKey(PhoneCalls)
+    resource = models.ForeignKey(PhoneCalls, on_delete=models.CASCADE)
     callee = models.CharField(blank=False, max_length=64)
     caller = models.CharField(blank=False, max_length=64)
     start_timestamp = models.DateTimeField(auto_now_add=True)
diff --git a/passerelle/apps/solis/migrations/0001_initial.py b/passerelle/apps/solis/migrations/0001_initial.py
index 656aab91..07395e37 100644
--- a/passerelle/apps/solis/migrations/0001_initial.py
+++ b/passerelle/apps/solis/migrations/0001_initial.py
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
                 ('name_id', models.CharField(max_length=256)),
                 ('user_id', models.CharField(max_length=64)),
                 ('code', models.CharField(max_length=64)),
-                ('resource', models.ForeignKey(to='solis.Solis')),
+                ('resource', models.ForeignKey(to='solis.Solis', on_delete=models.CASCADE)),
             ],
         ),
     ]
diff --git a/passerelle/apps/solis/models.py b/passerelle/apps/solis/models.py
index 844688fe..32eaa9db 100644
--- a/passerelle/apps/solis/models.py
+++ b/passerelle/apps/solis/models.py
@@ -611,7 +611,7 @@ class Solis(BaseResource):
 
 
 class SolisAPALink(models.Model):
-    resource = models.ForeignKey(Solis)
+    resource = models.ForeignKey(Solis, on_delete=models.CASCADE)
     name_id = models.CharField(blank=False, max_length=256)
     user_id = models.CharField(blank=False, max_length=64)
     code = models.CharField(blank=False, max_length=64)
@@ -619,7 +619,7 @@ class SolisAPALink(models.Model):
 
 
 class SolisRSALink(models.Model):
-    resource = models.ForeignKey(Solis)
+    resource = models.ForeignKey(Solis, on_delete=models.CASCADE)
     name_id = models.CharField(blank=False, max_length=256)
     user_id = models.CharField(blank=False, max_length=64)
     code = models.CharField(blank=False, max_length=64)
diff --git a/passerelle/apps/sp_fr/models.py b/passerelle/apps/sp_fr/models.py
index 0c3907ac..8c5cc224 100644
--- a/passerelle/apps/sp_fr/models.py
+++ b/passerelle/apps/sp_fr/models.py
@@ -524,7 +524,8 @@ class Mapping(models.Model):
     resource = models.ForeignKey(
         Resource,
         verbose_name=_('Resource'),
-        related_name='mappings')
+        related_name='mappings',
+        on_delete=models.CASCADE)
 
     procedure = models.CharField(
         verbose_name=_('Procedure'),
@@ -649,7 +650,8 @@ class Request(models.Model):
 
     resource = models.ForeignKey(
         Resource,
-        verbose_name=_('Resource'))
+        verbose_name=_('Resource'),
+        on_delete=models.CASCADE)
 
     created = models.DateTimeField(
         verbose_name=_('Created'),
diff --git a/passerelle/base/migrations/0001_initial.py b/passerelle/base/migrations/0001_initial.py
index 89d1acae..997fb3c6 100644
--- a/passerelle/base/migrations/0001_initial.py
+++ b/passerelle/base/migrations/0001_initial.py
@@ -52,13 +52,13 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='accessright',
             name='apiuser',
-            field=models.ForeignKey(to='base.ApiUser', verbose_name='API User'),
+            field=models.ForeignKey(to='base.ApiUser', verbose_name='API User', on_delete=models.CASCADE),
             preserve_default=True,
         ),
         migrations.AddField(
             model_name='accessright',
             name='resource_type',
-            field=models.ForeignKey(to='contenttypes.ContentType'),
+            field=models.ForeignKey(to='contenttypes.ContentType', on_delete=models.CASCADE),
             preserve_default=True,
         ),
     ]
diff --git a/passerelle/base/migrations/0006_resourcestatus.py b/passerelle/base/migrations/0006_resourcestatus.py
index 7c89c613..0eb064e5 100644
--- a/passerelle/base/migrations/0006_resourcestatus.py
+++ b/passerelle/base/migrations/0006_resourcestatus.py
@@ -20,7 +20,7 @@ class Migration(migrations.Migration):
                 ('start_timestamp', models.DateTimeField(auto_now_add=True)),
                 ('status', models.CharField(default=b'unknown', max_length=20, choices=[(b'unknown', 'Unknown'), (b'up', 'Up'), (b'down', 'Down')])),
                 ('message', models.CharField(max_length=500, blank=True)),
-                ('resource_type', models.ForeignKey(to='contenttypes.ContentType')),
+                ('resource_type', models.ForeignKey(to='contenttypes.ContentType', on_delete=models.CASCADE)),
             ],
             options={
                 'ordering': ['-start_timestamp'],
diff --git a/passerelle/base/models.py b/passerelle/base/models.py
index f797de85..5166d5b9 100644
--- a/passerelle/base/models.py
+++ b/passerelle/base/models.py
@@ -554,10 +554,10 @@ class BaseResource(models.Model):
 
 class AccessRight(models.Model):
     codename = models.CharField(max_length=100, verbose_name='codename')
-    resource_type = models.ForeignKey(ContentType)
+    resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
-    apiuser = models.ForeignKey(ApiUser, verbose_name=_('API User'))
+    apiuser = models.ForeignKey(ApiUser, verbose_name=_('API User'), on_delete=models.CASCADE)
 
     class Meta:
         permissions = (
@@ -572,7 +572,7 @@ class AccessRight(models.Model):
 
 
 class LoggingParameters(models.Model):
-    resource_type = models.ForeignKey(ContentType)
+    resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
     log_level = models.CharField(
@@ -618,7 +618,7 @@ def validate_notification_delays(value):
 
 
 class AvailabilityParameters(models.Model):
-    resource_type = models.ForeignKey(ContentType)
+    resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
     run_check = models.BooleanField(
@@ -653,7 +653,7 @@ class SkipJob(Exception):
 
 
 class Job(models.Model):
-    resource_type = models.ForeignKey(ContentType)
+    resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
     method_name = models.CharField(max_length=50)
@@ -714,7 +714,7 @@ STATUS_CHOICES = (
 )
 
 class ResourceStatus(models.Model):
-    resource_type = models.ForeignKey(ContentType)
+    resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     start_timestamp = models.DateTimeField(auto_now_add=True)
     status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='unknown')
diff --git a/passerelle/contrib/agoraplus/migrations/0001_initial.py b/passerelle/contrib/agoraplus/migrations/0001_initial.py
index a6546e68..fc2bb2e7 100644
--- a/passerelle/contrib/agoraplus/migrations/0001_initial.py
+++ b/passerelle/contrib/agoraplus/migrations/0001_initial.py
@@ -39,7 +39,7 @@ class Migration(migrations.Migration):
                 ('name_id', models.CharField(max_length=256)),
                 ('login', models.CharField(max_length=128)),
                 ('password', models.CharField(max_length=128)),
-                ('resource', models.ForeignKey(to='agoraplus.AgoraPlus')),
+                ('resource', models.ForeignKey(to='agoraplus.AgoraPlus', on_delete=models.CASCADE)),
             ],
             options={
             },
diff --git a/passerelle/contrib/agoraplus/migrations/0002_agoraplussas.py b/passerelle/contrib/agoraplus/migrations/0002_agoraplussas.py
index 6ddad1ec..6e87d6e6 100644
--- a/passerelle/contrib/agoraplus/migrations/0002_agoraplussas.py
+++ b/passerelle/contrib/agoraplus/migrations/0002_agoraplussas.py
@@ -20,7 +20,7 @@ class Migration(migrations.Migration):
                 ('kind', models.CharField(max_length=16, choices=[(b'ADULT', b'ADULT'), (b'CHILD', b'CHILD'), (b'CONTACT', b'CONTACT')])),
                 ('agoraplus_id', models.CharField(max_length=16, blank=True)),
                 ('value', jsonfield.fields.JSONField(default=dict, blank=True)),
-                ('resource', models.ForeignKey(to='agoraplus.AgoraPlus')),
+                ('resource', models.ForeignKey(to='agoraplus.AgoraPlus', on_delete=models.CASCADE)),
             ],
             options={
             },
diff --git a/passerelle/contrib/agoraplus/models.py b/passerelle/contrib/agoraplus/models.py
index cbdfe0c4..7b7cfb44 100644
--- a/passerelle/contrib/agoraplus/models.py
+++ b/passerelle/contrib/agoraplus/models.py
@@ -1014,7 +1014,7 @@ class AgoraPlusLink(models.Model):
     '''
     Link between a Publik user (name_id) and a Agora+ user (login/password)
     '''
-    resource = models.ForeignKey(AgoraPlus)
+    resource = models.ForeignKey(AgoraPlus, on_delete=models.CASCADE)
     name_id = models.CharField(blank=False, max_length=256)  # Publik user key
     login = models.CharField(blank=False, max_length=128)    # Agora+ user key
     password = models.CharField(blank=False, max_length=128) # Agora+ auth
@@ -1032,7 +1032,7 @@ class AgoraPlusSas(models.Model):
     '''
     Stores informations before sending in Agora +
     '''
-    resource = models.ForeignKey(AgoraPlus)
+    resource = models.ForeignKey(AgoraPlus, on_delete=models.CASCADE)
     name_id = models.CharField(blank=False, max_length=256)  # Publik user key
     kind = models.CharField(blank=False, max_length=16, choices=SAS_KIND_OF_VALUES)
     agoraplus_id = models.CharField(blank=True, max_length=16)
diff --git a/passerelle/contrib/dpark/migrations/0001_initial.py b/passerelle/contrib/dpark/migrations/0001_initial.py
index 9569c1c7..c836e9ee 100644
--- a/passerelle/contrib/dpark/migrations/0001_initial.py
+++ b/passerelle/contrib/dpark/migrations/0001_initial.py
@@ -37,7 +37,7 @@ class Migration(migrations.Migration):
                 ('filenumber', models.CharField(max_length=128)),
                 ('badgenumber', models.CharField(max_length=128)),
                 ('cardnumber', models.CharField(max_length=128)),
-                ('resource', models.ForeignKey(to='dpark.DPark')),
+                ('resource', models.ForeignKey(to='dpark.DPark', on_delete=models.CASCADE)),
             ],
         ),
     ]
diff --git a/passerelle/contrib/dpark/models.py b/passerelle/contrib/dpark/models.py
index 3295a47b..0a4fe342 100644
--- a/passerelle/contrib/dpark/models.py
+++ b/passerelle/contrib/dpark/models.py
@@ -487,7 +487,7 @@ class Pairing(models.Model):
     INFO_CACHE_DURATION = 5 * 60
     PAYMENT_INFO_CACHE_DURATION = 20 * 60
 
-    resource = models.ForeignKey(DPark)
+    resource = models.ForeignKey(DPark, on_delete=models.CASCADE)
     nameid = models.CharField(blank=False, max_length=256)
     lastname = models.CharField(blank=False, max_length=128)
     firstnames = models.CharField(blank=False, max_length=128)
diff --git a/passerelle/contrib/planitech/models.py b/passerelle/contrib/planitech/models.py
index 2e3e9e1b..03d7728f 100644
--- a/passerelle/contrib/planitech/models.py
+++ b/passerelle/contrib/planitech/models.py
@@ -822,7 +822,7 @@ class Pairing(models.Model):
     class Meta:
         unique_together = (('resource', 'name_id'), ('resource', 'external_id'),)
 
-    resource = models.ForeignKey(PlanitechConnector)
+    resource = models.ForeignKey(PlanitechConnector, on_delete=models.CASCADE)
     name_id = models.CharField(blank=False, max_length=256)
     external_id = models.CharField(blank=False, max_length=256)
     created = models.DateTimeField(auto_now_add=True)
diff --git a/passerelle/contrib/teamnet_axel/migrations/0001_initial.py b/passerelle/contrib/teamnet_axel/migrations/0001_initial.py
index b7ac49b7..cc918cf6 100644
--- a/passerelle/contrib/teamnet_axel/migrations/0001_initial.py
+++ b/passerelle/contrib/teamnet_axel/migrations/0001_initial.py
@@ -45,7 +45,7 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='link',
             name='resource',
-            field=models.ForeignKey(to='teamnet_axel.Management'),
+            field=models.ForeignKey(to='teamnet_axel.Management', on_delete=models.CASCADE),
             preserve_default=True,
         ),
     ]
diff --git a/passerelle/contrib/teamnet_axel/migrations/0006_rename_model_2.py b/passerelle/contrib/teamnet_axel/migrations/0006_rename_model_2.py
index 0521e152..2cceed1b 100644
--- a/passerelle/contrib/teamnet_axel/migrations/0006_rename_model_2.py
+++ b/passerelle/contrib/teamnet_axel/migrations/0006_rename_model_2.py
@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='link',
             name='resource',
-            field=models.ForeignKey(to='teamnet_axel.TeamnetAxel'),
+            field=models.ForeignKey(to='teamnet_axel.TeamnetAxel', on_delete=models.CASCADE),
         ),
     ]
diff --git a/passerelle/contrib/teamnet_axel/models.py b/passerelle/contrib/teamnet_axel/models.py
index 9a9ddd62..7c763fcf 100644
--- a/passerelle/contrib/teamnet_axel/models.py
+++ b/passerelle/contrib/teamnet_axel/models.py
@@ -351,7 +351,7 @@ class TeamnetAxel(BaseResource):
 
 
 class Link(models.Model):
-    resource = models.ForeignKey(TeamnetAxel)
+    resource = models.ForeignKey(TeamnetAxel, on_delete=models.CASCADE)
     nameid = models.CharField(blank=False, max_length=256)
     login = models.CharField(blank=False, max_length=128)
     pwd = models.CharField(blank=False, max_length=128)
-- 
2.20.1

