Skip to content

Commit 22348f4

Browse files
rando128rando128
authored andcommitted
improve migration for existing UUIDField
1 parent 35afccb commit 22348f4

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

back/back/apps/people/migrations/0007_user_sender_uuid.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from django.db import migrations, models
55

66

7+
def create_uuid(apps, schema_editor):
8+
User = apps.get_model("people", "User")
9+
for user in User.objects.all():
10+
user.sender_uuid = uuid.uuid4()
11+
user.save(update_fields=["sender_uuid"])
12+
713
class Migration(migrations.Migration):
814

915
dependencies = [
@@ -19,7 +25,19 @@ class Migration(migrations.Migration):
1925
default=uuid.uuid4,
2026
editable=False,
2127
help_text="Universal sender identifier for lefebvre-chatfaq integration",
22-
unique=True,
28+
null=True, # Change unique=True to null=True here
29+
),
30+
),
31+
migrations.RunPython(create_uuid, reverse_code=migrations.RunPython.noop),
32+
migrations.AlterField(
33+
model_name="user",
34+
name="sender_uuid",
35+
field=models.UUIDField(
36+
db_index=True,
37+
default=uuid.uuid4,
38+
editable=False,
39+
help_text="Universal sender identifier for lefebvre-chatfaq integration",
40+
unique=True, # This one remains unique=True
2341
),
2442
),
2543
]

0 commit comments

Comments
 (0)