Home:ALL Converter>migrate django model primary key UUID field to CharField

migrate django model primary key UUID field to CharField

Ask Time:2020-09-30T00:54:04         Author:Jose

Json Formatter

I need to change the id field size on an oracle database to support storing longer id's. By default using the UUIDField in django creates a table with varchar field of 32 bytes but we now need it to store ids generated by uuid.uui4 and of supplied id's of character lengths up to 80. What is the least hacky way to do this in django so that the migrations are consistent across environments while keeping foreign key relationships in other models?

class CurrentModel(models.Model):
   id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

class desiredModel(models.Model):
   id = models.CharField(max_length=80, primary_key=True, default=uuid.uuid4)

This was the change we made but oracle throws an error when applying the migration django.db.utils.DatabaseError: ORA-01430: column being added already exists in table

Author:Jose,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64124218/migrate-django-model-primary-key-uuid-field-to-charfield
yy