Changing the primary key of a model in Django

I had to change the primary key of a django model, and I wanted to create a migration for this. The previous model was using django ids.

The migrations will need to do the following things:

Create the new field in the model

    uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)

To generate the migrations I did django-admin makemigrations. The migration looks like this:


Running the tests, I figured out that the URLs will need to be updated as well. I found a regexp for UUIDs

#django, #orm, #migrations - Posté dans la catégorie code