Fix series.project migration logic
andy.doan at linaro.org
Thu Jan 26 07:17:29 AEDT 2017
The migration logic seems slightly off for 2 reasons:
1) If you already have series objects in your database, then adding a
non-nullable foreign key to projects will fail.
2) This may just be a remnant of my development database, but I had
series entries with no patches.
I think part #1 is *required*. I'm not totally sure about #2, but it
Signed-off-by: Andy Doan <andy.doan at linaro.org>
patchwork/migrations/0016_series_project.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/patchwork/migrations/0016_series_project.py b/patchwork/migrations/0016_series_project.py
index befd695..c4874f9 100644
@@ -16,8 +16,10 @@ def forward(apps, schema_editor):
series.project = series.cover_letter.project
- series.project = series.patches.first().project
+ patch = series.patches.first()
+ if patch:
+ series.project = patch.project
# a series without patches or cover letters should not exist.
# Delete it.
@@ -38,7 +40,7 @@ class Migration(migrations.Migration):
- field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='series', to='patchwork.Project'),
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='series', to='patchwork.Project'),
More information about the Patchwork