I have model AAA with UUID as primary key. Many models have relation to this model.
Now I want to migrate them to use Slug as this primary key, to keep slug value in database as a reference.
What will be the correct way to do that?
Thinking that this might be some multi-step migration. But having many tables that reference to AAA would like to avoid blocking whole db for much time or any other issues in production.
from django.db import models
from django_extensions.db.fields import AutoSlugField
from model_utils.models import UUIDModel
# Django models example
class AAA(models.Model):
id = UUIDField(primary_key=True, version=4, editable=False)
title = models.CharField(max_length=255, unique=True)
slug = AutoSlugField(populate_from='title', primary_key=False)
class BBB(models.Model):
aaa = models.ForeignKey(AAA, on_delete=models.CASCADE)
# ... other fields here ...