I'm implementing this answer to add an automatic UUIDField
to a database with existing rows.
The suggested adjustments to the data migration are:
from django_extensions.utils import uuid
def forwards(self, orm):
for item in orm['mypp.myclass'].objects.all():
if not item.uuid:
item.uuid = uuid.uuid4() #creates a random GUID
item.save()
def backwards(self, orm):
for item in orm['mypp.myclass'].objects.all():
if item.uuid:
item.uuid = None
item.save()
However, I don't want to allow blank=True
to my model. How would I adjust the backwards()
function in that case? The current item.uuid = None
would no longer work...