#Updating Model of Existing Database
10 messages ยท Page 1 of 1 (latest)
What kind of update do you need to do? Add fields, modify fields? Something else?
At a very high level. It's running makemigrations, the migrate
I wouldn't recommend that (changing the PK to a uuid)
I would recommend adding the uuid field with unique set to True which will achieve a similar thing with less pain.
Okay cool. Why do you advise against it?
It means you would need to update everything related model that is linked via a Foreign Key and Many2Many Fields. Not to mention the broad assumption that PKs are integers in various places within Django. Also doing such a migration effectively means you need to create a whole new table, migrate the data, then drop the old one.
Where as adding a field is much simpler migration process.
- Add the field with null=True, unique=True
- Create an empty migration and add code to populate existing rows with UUIDs
- Add a final migration to change null=False to ensure uuids are unique going forward.
Ah I see. Many thanks, kind stranger ๐
Your welcome ๐