|
@ -5,6 +5,13 @@ import uuid |
|
|
from django.db import migrations, models |
|
|
from django.db import migrations, models |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_uuid(apps, schema_editor): |
|
|
|
|
|
Example = apps.get_model("api", "example") |
|
|
|
|
|
for example in Example.objects.all(): |
|
|
|
|
|
example.uuid = uuid.uuid4() |
|
|
|
|
|
example.save(update_fields=["uuid"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration): |
|
|
class Migration(migrations.Migration): |
|
|
|
|
|
|
|
|
dependencies = [ |
|
|
dependencies = [ |
|
@ -15,6 +22,10 @@ class Migration(migrations.Migration): |
|
|
migrations.AddField( |
|
|
migrations.AddField( |
|
|
model_name="example", |
|
|
model_name="example", |
|
|
name="uuid", |
|
|
name="uuid", |
|
|
field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True), |
|
|
|
|
|
|
|
|
field=models.UUIDField(editable=False, blank=True, null=True), |
|
|
|
|
|
), |
|
|
|
|
|
migrations.RunPython(create_uuid, reverse_code=migrations.RunPython.noop), |
|
|
|
|
|
migrations.AlterField( |
|
|
|
|
|
model_name="example", name="uuid", field=models.UUIDField(default=uuid.uuid4, db_index=True, unique=True) |
|
|
), |
|
|
), |
|
|
] |
|
|
] |