Opened 19 months ago

Last modified 3 months ago

#34151 assigned Bug

django.db.migrations doesn't update *_id column data type in related table when changing pk type of linked models. — at Version 1

Reported by: STANISLAV LEPEKHOV Owned by: nobody
Component: Migrations Version: 4.1
Severity: Normal Keywords: migrations pk uuid relation
Cc: Sarah Abderemane Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by STANISLAV LEPEKHOV)

Hello!
When i changed this models:

class StoreChain(models.Model):
    places = models.ManyToManyField(Place, blank=True)

class Place(models.Model):
    pass

to this edition (set pk with uuid type):

class StoreChain(models.Model):
    uid = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, unique=True)
    places = models.ManyToManyField(Place, blank=True)

class Place(models.Model):
    uid = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, unique=True)

Django creates a migration file that affects only the model tables, while the relationship table remains unchanged, which will cause an error, because the data type of the _ID fields in it also needs to be changed:
https://i.ibb.co/XZYjvYp/hU0HJyqF.jpg

Change History (1)

comment:1 by STANISLAV LEPEKHOV, 19 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top