From 47d38e1ccaf80cfd20fc83dc25e98f5beb347c68 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 1 Dec 2020 10:24:51 +1100 Subject: [PATCH] Change delete behaviour for parent build item - was causing database integrity errors when a parent build existed --- .../migrations/0024_auto_20201201_1023.py | 20 +++++++++++++++++++ InvenTree/build/models.py | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 InvenTree/build/migrations/0024_auto_20201201_1023.py diff --git a/InvenTree/build/migrations/0024_auto_20201201_1023.py b/InvenTree/build/migrations/0024_auto_20201201_1023.py new file mode 100644 index 0000000000..fde4114af5 --- /dev/null +++ b/InvenTree/build/migrations/0024_auto_20201201_1023.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.7 on 2020-11-30 23:23 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0023_auto_20201110_0911'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='parent', + field=mptt.fields.TreeForeignKey(blank=True, help_text='BuildOrder to which this build is allocated', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='build.Build', verbose_name='Parent Build'), + ), + ] diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index a18471ccc6..8616e11b2a 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -83,9 +83,10 @@ class Build(MPTTModel): help_text=_('Brief description of the build') ) + # TODO - Perhaps delete the build "tree" parent = TreeForeignKey( 'self', - on_delete=models.DO_NOTHING, + on_delete=models.SET_NULL, blank=True, null=True, related_name='children', verbose_name=_('Parent Build'),