diff --git a/zerver/migrations/0324_fix_deletion_cascade_behavior.py b/zerver/migrations/0324_fix_deletion_cascade_behavior.py new file mode 100644 index 0000000000..5c5e408a35 --- /dev/null +++ b/zerver/migrations/0324_fix_deletion_cascade_behavior.py @@ -0,0 +1,56 @@ +# Generated by Django 3.2 on 2021-05-07 01:00 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("zerver", "0323_show_starred_message_counts"), + ] + + operations = [ + migrations.AlterField( + model_name="realm", + name="notifications_stream", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="zerver.stream", + ), + ), + migrations.AlterField( + model_name="realm", + name="signup_notifications_stream", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="zerver.stream", + ), + ), + migrations.AlterField( + model_name="userprofile", + name="default_events_register_stream", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="zerver.stream", + ), + ), + migrations.AlterField( + model_name="userprofile", + name="default_sending_stream", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="zerver.stream", + ), + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 35f2975e63..e66fa1b13e 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -375,14 +375,14 @@ class Realm(models.Model): related_name="+", null=True, blank=True, - on_delete=CASCADE, + on_delete=models.SET_NULL, ) signup_notifications_stream: Optional["Stream"] = models.ForeignKey( "Stream", related_name="+", null=True, blank=True, - on_delete=CASCADE, + on_delete=models.SET_NULL, ) MESSAGE_RETENTION_SPECIAL_VALUES_MAP = { @@ -1266,13 +1266,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): "zerver.Stream", null=True, related_name="+", - on_delete=CASCADE, + on_delete=models.SET_NULL, ) default_events_register_stream: Optional["Stream"] = models.ForeignKey( "zerver.Stream", null=True, related_name="+", - on_delete=CASCADE, + on_delete=models.SET_NULL, ) default_all_public_streams: bool = models.BooleanField(default=False)