You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
869 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. # Generated by Django 3.2.8 on 2021-11-08 06:06
  2. import uuid
  3. from django.db import migrations, models
  4. def create_uuid(apps, schema_editor):
  5. Example = apps.get_model("api", "example")
  6. for example in Example.objects.all():
  7. example.uuid = uuid.uuid4()
  8. example.save(update_fields=["uuid"])
  9. class Migration(migrations.Migration):
  10. dependencies = [
  11. ("api", "0016_auto_20211018_0556"),
  12. ]
  13. operations = [
  14. migrations.AddField(
  15. model_name="example",
  16. name="uuid",
  17. field=models.UUIDField(editable=False, blank=True, null=True),
  18. ),
  19. migrations.RunPython(create_uuid, reverse_code=migrations.RunPython.noop),
  20. migrations.AlterField(
  21. model_name="example", name="uuid", field=models.UUIDField(default=uuid.uuid4, db_index=True, unique=True)
  22. ),
  23. ]