[PATCH 03/19] migrations: Explicitly set 'on_delete'

Stephen Finucane stephen at that.guru
Thu May 11 05:45:12 AEST 2017


This raises warnings for Django 1.9 and will be mandatory in Django 2.0.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/migrations/0001_initial.py               | 34 +++++++++++-----------
 .../0002_fix_patch_state_default_values.py         |  3 +-
 patchwork/migrations/0003_add_check_model.py       |  5 ++--
 .../migrations/0004_add_delegation_rule_model.py   |  5 ++--
 patchwork/migrations/0006_add_patch_diff.py        |  9 ++++--
 patchwork/migrations/0009_add_submission_model.py  |  7 ++++-
 patchwork/migrations/0011_remove_temp_fields.py    | 24 ++++++++++-----
 patchwork/migrations/0012_add_coverletter_model.py |  3 +-
 8 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/patchwork/migrations/0001_initial.py b/patchwork/migrations/0001_initial.py
index 812558a..374b188 100644
--- a/patchwork/migrations/0001_initial.py
+++ b/patchwork/migrations/0001_initial.py
@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('name', models.CharField(max_length=50)),
                 ('public', models.BooleanField(default=False)),
-                ('owner', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
             ],
         ),
         migrations.CreateModel(
@@ -29,7 +29,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('order', models.IntegerField()),
-                ('bundle', models.ForeignKey(to='patchwork.Bundle')),
+                ('bundle', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Bundle')),
             ],
             options={
                 'ordering': ['order'],
@@ -57,7 +57,7 @@ class Migration(migrations.Migration):
                 ('key', patchwork.models.HashField(max_length=40)),
                 ('date', models.DateTimeField(default=datetime.datetime.now)),
                 ('active', models.BooleanField(default=True)),
-                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)),
+                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, null=True)),
             ],
         ),
         migrations.CreateModel(
@@ -153,47 +153,47 @@ class Migration(migrations.Migration):
                 ('send_email', models.BooleanField(default=False, help_text=b'Selecting this option allows patchwork to send email on your behalf')),
                 ('patches_per_page', models.PositiveIntegerField(default=100, help_text=b'Number of patches to display per page')),
                 ('maintainer_projects', models.ManyToManyField(related_name='maintainer_project', to='patchwork.Project')),
-                ('primary_project', models.ForeignKey(blank=True, to='patchwork.Project', null=True)),
-                ('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL)),
+                ('primary_project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to='patchwork.Project', null=True)),
+                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
             ],
         ),
         migrations.CreateModel(
             name='PatchChangeNotification',
             fields=[
-                ('patch', models.OneToOneField(primary_key=True, serialize=False, to='patchwork.Patch')),
+                ('patch', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='patchwork.Patch')),
                 ('last_modified', models.DateTimeField(default=datetime.datetime.now)),
-                ('orig_state', models.ForeignKey(to='patchwork.State')),
+                ('orig_state', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.State')),
             ],
         ),
         migrations.AddField(
             model_name='patchtag',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Patch'),
         ),
         migrations.AddField(
             model_name='patchtag',
             name='tag',
-            field=models.ForeignKey(to='patchwork.Tag'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Tag'),
         ),
         migrations.AddField(
             model_name='patch',
             name='delegate',
-            field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, blank=True, to=settings.AUTH_USER_MODEL, null=True),
         ),
         migrations.AddField(
             model_name='patch',
             name='project',
-            field=models.ForeignKey(to='patchwork.Project'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Project'),
         ),
         migrations.AddField(
             model_name='patch',
             name='state',
-            field=models.ForeignKey(to='patchwork.State'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.State'),
         ),
         migrations.AddField(
             model_name='patch',
             name='submitter',
-            field=models.ForeignKey(to='patchwork.Person'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Person'),
         ),
         migrations.AddField(
             model_name='patch',
@@ -203,17 +203,17 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='comment',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Patch'),
         ),
         migrations.AddField(
             model_name='comment',
             name='submitter',
-            field=models.ForeignKey(to='patchwork.Person'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Person'),
         ),
         migrations.AddField(
             model_name='bundlepatch',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Patch'),
         ),
         migrations.AddField(
             model_name='bundle',
@@ -223,7 +223,7 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='bundle',
             name='project',
-            field=models.ForeignKey(to='patchwork.Project'),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Project'),
         ),
         migrations.AlterUniqueTogether(
             name='patchtag',
diff --git a/patchwork/migrations/0002_fix_patch_state_default_values.py b/patchwork/migrations/0002_fix_patch_state_default_values.py
index 4887935..d187dff 100644
--- a/patchwork/migrations/0002_fix_patch_state_default_values.py
+++ b/patchwork/migrations/0002_fix_patch_state_default_values.py
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals
 
 from django.db import models, migrations
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -14,6 +15,6 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='patch',
             name='state',
-            field=models.ForeignKey(to='patchwork.State', null=True),
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.State', null=True),
         ),
     ]
diff --git a/patchwork/migrations/0003_add_check_model.py b/patchwork/migrations/0003_add_check_model.py
index 50bd72b..8be9631 100644
--- a/patchwork/migrations/0003_add_check_model.py
+++ b/patchwork/migrations/0003_add_check_model.py
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
 from django.db import models, migrations
 import datetime
 from django.conf import settings
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -23,8 +24,8 @@ class Migration(migrations.Migration):
                 ('target_url', models.URLField(help_text=b'The target URL to associate with this check. This should be specific to the patch.', null=True, blank=True)),
                 ('description', models.TextField(help_text=b'A brief description of the check.', null=True, blank=True)),
                 ('context', models.CharField(default=b'default', max_length=255, null=True, help_text=b'A label to discern check from checks of other testing systems.', blank=True)),
-                ('patch', models.ForeignKey(to='patchwork.Patch')),
-                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+                ('patch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Patch')),
+                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
             ],
             options={
             },
diff --git a/patchwork/migrations/0004_add_delegation_rule_model.py b/patchwork/migrations/0004_add_delegation_rule_model.py
index cec9014..7fd0bc9 100644
--- a/patchwork/migrations/0004_add_delegation_rule_model.py
+++ b/patchwork/migrations/0004_add_delegation_rule_model.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
 
 from django.db import migrations, models
 from django.conf import settings
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -19,8 +20,8 @@ class Migration(migrations.Migration):
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('path', models.CharField(max_length=255)),
                 ('priority', models.IntegerField(default=0)),
-                ('project', models.ForeignKey(to='patchwork.Project')),
-                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='patchwork.Project')),
+                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
             ],
             options={
                 'ordering': ['-priority', 'path'],
diff --git a/patchwork/migrations/0006_add_patch_diff.py b/patchwork/migrations/0006_add_patch_diff.py
index 926ef95..73fc6ac 100644
--- a/patchwork/migrations/0006_add_patch_diff.py
+++ b/patchwork/migrations/0006_add_patch_diff.py
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals
 
 from django.db import migrations, models
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -24,8 +25,10 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='comment',
             name='patch',
-            field=models.ForeignKey(related_query_name=b'comment',
-                                    related_name='comments',
-                                    to='patchwork.Patch'),
+            field=models.ForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                related_query_name=b'comment',
+                related_name='comments',
+                to='patchwork.Patch'),
         ),
     ]
diff --git a/patchwork/migrations/0009_add_submission_model.py b/patchwork/migrations/0009_add_submission_model.py
index 6bb68fb..ebd85f9 100644
--- a/patchwork/migrations/0009_add_submission_model.py
+++ b/patchwork/migrations/0009_add_submission_model.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
 
 from django.conf import settings
 from django.db import migrations, models
+import django.db.models.deletion
 
 import patchwork.models
 
@@ -55,6 +56,7 @@ class Migration(migrations.Migration):
             fields=[
                 ('submission_ptr', models.OneToOneField(
                     parent_link=True, auto_created=True, primary_key=True,
+                    on_delete=django.db.models.deletion.CASCADE,
                     serialize=False, to='patchwork.Submission')),
                 ('diff2', models.TextField(null=True, blank=True)),
                 ('commit_ref2', models.CharField(
@@ -66,8 +68,11 @@ class Migration(migrations.Migration):
                 ('tags2', models.ManyToManyField(
                     to='patchwork.Tag', through='patchwork.PatchTag')),
                 ('delegate2', models.ForeignKey(
+                    on_delete=django.db.models.deletion.CASCADE,
                     blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-                ('state2', models.ForeignKey(to='patchwork.State')),
+                ('state2', models.ForeignKey(
+                    on_delete=django.db.models.deletion.CASCADE,
+                    to='patchwork.State')),
                 ('archived2', models.BooleanField(default=False)),
                 ('hash2', patchwork.models.HashField(
                     max_length=40, null=True, blank=True)),
diff --git a/patchwork/migrations/0011_remove_temp_fields.py b/patchwork/migrations/0011_remove_temp_fields.py
index 6b159c5..57475f9 100644
--- a/patchwork/migrations/0011_remove_temp_fields.py
+++ b/patchwork/migrations/0011_remove_temp_fields.py
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals
 
 from django.db import migrations, models
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -94,28 +95,37 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='bundlepatch',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                to='patchwork.Patch'),
         ),
         migrations.AlterField(
             model_name='check',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                to='patchwork.Patch'),
         ),
         migrations.AlterField(
             model_name='patch',
             name='state',
-            field=models.ForeignKey(to='patchwork.State', null=True),
+            field=models.ForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                to='patchwork.State', null=True),
         ),
         migrations.AlterField(
             model_name='patchchangenotification',
             name='patch',
-            field=models.OneToOneField(primary_key=True,
-                                       serialize=False,
-                                       to='patchwork.Patch'),
+            field=models.OneToOneField(
+                primary_key=True, serialize=False,
+                on_delete=django.db.models.deletion.CASCADE,
+                to='patchwork.Patch'),
         ),
         migrations.AlterField(
             model_name='patchtag',
             name='patch',
-            field=models.ForeignKey(to='patchwork.Patch'),
+            field=models.ForeignKey(
+                on_delete=django.db.models.deletion.CASCADE,
+                to='patchwork.Patch'),
         ),
     ]
diff --git a/patchwork/migrations/0012_add_coverletter_model.py b/patchwork/migrations/0012_add_coverletter_model.py
index ec0f785..819cee9 100644
--- a/patchwork/migrations/0012_add_coverletter_model.py
+++ b/patchwork/migrations/0012_add_coverletter_model.py
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals
 
 from django.db import migrations, models
+import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
@@ -14,7 +15,7 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name='CoverLetter',
             fields=[
-                ('submission_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='patchwork.Submission')),
+                ('submission_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='patchwork.Submission')),
             ],
             options={
                 'abstract': False,
-- 
2.9.3



More information about the Patchwork mailing list