Migrating from Integer to UUID as Primary Key Without Breaking Relationships

Hello everyone,

I need to migrate my database from using an IntegerField as the primary key to UUIDField. The problem is that my database has many relationships with foreign keys referencing these primary keys.

I want to ensure that the migration preserves data integrity and doesn’t break existing relationships.

What is the best way to perform this migration in Django without losing data or breaking foreign key constraints?

Any guidance, best practices, or step-by-step approaches would be greatly appreciated!

Thanks in advance!

Welcome @adoumasseo !

For a couple of different ideas, see the thread at Error when I change id to UUID

There are other topics where this has been discussed - you might want to search to see what other ideas you might find.

1 Like