mirror of https://github.com/zulip/zulip.git
models: Add unique constraint on RealmUserDefault.realm.
This model is by designed intended to exist on a 1:1 relationship with Realms, and we attempt to ensure that with application code, but we should have a unique constraint too, since a database with duplicate such entries would be corrupted. We do this via the standard Django OneToOneField.
This commit is contained in:
parent
760cfcc603
commit
73bc5480f3
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.2.12 on 2022-03-05 02:59
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("zerver", "0377_message_edit_history_format"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="realmuserdefault",
|
||||
name="realm",
|
||||
field=models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="zerver.realm"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1604,7 +1604,7 @@ class RealmUserDefault(UserBaseSettings):
|
|||
"""
|
||||
|
||||
id: int = models.AutoField(auto_created=True, primary_key=True, verbose_name="ID")
|
||||
realm: Realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
||||
realm: Realm = models.OneToOneField(Realm, on_delete=CASCADE)
|
||||
|
||||
|
||||
class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
|
||||
|
|
Loading…
Reference in New Issue