diff --git a/dje/management/commands/flushdataset.py b/dje/management/commands/flushdataset.py index 9d642b3f..de2f6b80 100644 --- a/dje/management/commands/flushdataset.py +++ b/dje/management/commands/flushdataset.py @@ -37,6 +37,7 @@ def add_arguments(self, parser): def handle(self, *args, **options): super().handle(*args, **options) + dataspace = self.dataspace models = ALL_MODELS[:] # Making a copy to not impact the original list models += WORKFLOW_MODELS @@ -52,7 +53,11 @@ def handle(self, *args, **options): Webhook, ]) - dataspace = self.dataspace + # Clear the associated_product_relation_status FK values so the + # ProductRelationStatus model can be flushed before the UsagePolicy model. + usage_policies = UsagePolicy.objects.filter(dataspace=dataspace) + usage_policies.update(associated_product_relation_status=None) + for model_class in models: qs = get_unsecured_manager(model_class).filter(dataspace=dataspace) if options['verbosity'] > 1: diff --git a/dje/migrations/0003_alter_dejacodeuser_homepage_layout.py b/dje/migrations/0003_alter_dejacodeuser_homepage_layout.py new file mode 100644 index 00000000..aa005643 --- /dev/null +++ b/dje/migrations/0003_alter_dejacodeuser_homepage_layout.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.3 on 2024-05-08 08:26 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("dje", "0002_initial"), + ("reporting", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="dejacodeuser", + name="homepage_layout", + field=models.ForeignKey( + blank=True, + help_text="Select a Card layout that provides the query results on the DejaCode homepage that are useful and interesting to you.", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + serialize=False, + to="reporting.cardlayout", + ), + ), + ] diff --git a/dje/models.py b/dje/models.py index 1d908cd0..9499446d 100644 --- a/dje/models.py +++ b/dje/models.py @@ -1512,7 +1512,7 @@ class DejacodeUser(AbstractUser): null=True, blank=True, related_name="+", - on_delete=models.CASCADE, + on_delete=models.SET_NULL, serialize=False, help_text=_( "Select a Card layout that provides the query results on the "