[Django] #34151: django.db.migrations doesn't update *_id column data type in related table when changing pk type of linked models.

3 views
Skip to first unread message

Django

unread,
Nov 11, 2022, 8:40:27 AM11/11/22
to django-...@googlegroups.com
#34151: django.db.migrations doesn't update *_id column data type in related table
when changing pk type of linked models.
-------------------------------------+-------------------------------------
Reporter: STANISLAV | Owner: nobody
LEPEKHOV |
Type: Bug | Status: new
Component: Core | Version: 4.1
(Management commands) | Keywords: migrations pk uuid
Severity: Normal | relation
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello!
When i changed this models:

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

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

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:
[[Image(https://i.ibb.co/XZYjvYp/hU0HJyqF.jpg)]]

--
Ticket URL: <https://code.djangoproject.com/ticket/34151>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 11, 2022, 9:10:50 AM11/11/22
to django-...@googlegroups.com
#34151: django.db.migrations doesn't update *_id column data type in related table
when changing pk type of linked models.
-------------------------------------+-------------------------------------
Reporter: STANISLAV LEPEKHOV | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 4.1
commands) |
Severity: Normal | Resolution:
Keywords: migrations pk uuid | Triage Stage:
relation | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by STANISLAV LEPEKHOV:

Old description:

> Hello!
> When i changed this models:
>
> {{{
> class StoreChain(models.Model):
> places = models.ManyToManyField(Place, blank=True)
>
> class Place(models.Model):
> uid = models.UUIDField(default=uuid.uuid4, editable=False,
> primary_key=True, unique=True)
> }}}
>
> 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:
> [[Image(https://i.ibb.co/XZYjvYp/hU0HJyqF.jpg)]]

New description:

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:
[[Image(https://i.ibb.co/XZYjvYp/hU0HJyqF.jpg)]]

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34151#comment:1>

Django

unread,
Nov 11, 2022, 9:23:45 AM11/11/22
to django-...@googlegroups.com
#34151: django.db.migrations doesn't update *_id column data type in related table
when changing pk type of linked models.
-------------------------------------+-------------------------------------
Reporter: STANISLAV LEPEKHOV | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 4.1
commands) |
Severity: Normal | Resolution:
Keywords: migrations pk uuid | Triage Stage: Accepted
relation |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by STANISLAV LEPEKHOV):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34151#comment:2>

Django

unread,
Nov 11, 2022, 9:45:36 AM11/11/22
to django-...@googlegroups.com
#34151: django.db.migrations doesn't update *_id column data type in related table
when changing pk type of linked models.
-------------------------------------+-------------------------------------
Reporter: STANISLAV LEPEKHOV | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 4.1
commands) |
Severity: Normal | Resolution:
Keywords: migrations pk uuid | Triage Stage:
relation | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* easy: 1 => 0
* stage: Accepted => Unreviewed


Comment:

Thanks for the report. Please don't accept your own tickets.

--
Ticket URL: <https://code.djangoproject.com/ticket/34151#comment:3>

Reply all
Reply to author
Forward
0 new messages