简体   繁体   中英

migrate django model primary key UUID field to CharField

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

我不是 Django 专家,但您可能需要使用 Django 的AlterField选项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM