[Django] #36343: Uprading to Django 5.2 from Django 5.1.7 creates a new migration for a self referencing through model

26 views
Skip to first unread message

Django

unread,
Apr 21, 2025, 10:12:06 AM4/21/25
to django-...@googlegroups.com
#36343: Uprading to Django 5.2 from Django 5.1.7 creates a new migration for a self
referencing through model
---------------------------------+-----------------------------------------
Reporter: Mark Chackerian | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
I have a model with a self-referential through model like


{{{
class Cad((models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
cads: models.ManyToManyField = models.ManyToManyField(
"self", symmetrical=False, through="CadChild",
through_fields=("parent", "child")
)
...

class CadChild(models.Model):
"""A through model for Cad parent/child many-to-many relationships."""

parent = models.ForeignKey(
Cad,
on_delete=models.CASCADE,
related_name="parent_cad_set",
)
child = models.ForeignKey(
Cad,
on_delete=models.CASCADE,
related_name="child_cad_set",
)

}}}


When I upgraded from 5.1.7 to 5.2 I needed to created to create a new
migration, which looked like:

{{{
# Generated by Django 5.2 on 2025-04-21 13:25

from django.db import migrations, models




class Migration(migrations.Migration):

dependencies = [
('projects',
'0012_documentpagetheme_documentpagethemeuserdefault'),
]

operations = [
migrations.AlterField(
model_name='cad',
name='cads',
field=models.ManyToManyField(through='projects.CadChild',
through_fields=('parent', 'child'), to='projects.cad'),
),
]

}}}


----

This may be intended behavior but I can't find any reference to this
change in the release notes.
--
Ticket URL: <https://code.djangoproject.com/ticket/36343>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 21, 2025, 10:35:37 AM4/21/25
to django-...@googlegroups.com
#36343: Uprading to Django 5.2 from Django 5.1.7 creates a new migration for a self
referencing through model
---------------------------------+--------------------------------------
Reporter: Mark Chackerian | Owner: (none)
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Simon Charette):

* resolution: => invalid
* status: new => closed

Comment:

Thank you for your report, it is effectively intended.

Prior to Django 5.2 there was a bug that prevented the appropriate
tracking of `through_fields` in migrations #36061
(b13b8684a04d0bc1081104c5973c62c27dc673b0) which could cause crashes or
data corruptions if the involved models were used in data migrations (e.g.
through `RunPython`).

We don't document bug fixes in release notes hence why you couldn't find
it.
--
Ticket URL: <https://code.djangoproject.com/ticket/36343#comment:1>
Reply all
Reply to author
Forward
0 new messages