[Django] #33119: Change casing of a model's name cause endless creation of migrations

7 views
Skip to first unread message

Django

unread,
Sep 18, 2021, 2:55:01 AM9/18/21
to django-...@googlegroups.com
#33119: Change casing of a model's name cause endless creation of migrations
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
AliGhotbizadeh |
Type: Bug | Status: new
Component: | Version: 3.2
Migrations | Keywords:
Severity: Normal | M2M,RenameModel,deconstruct
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have models like

{{{
#!python
class DataCenter(models.Model):
title = models.CharField(max_length=100)

class Project(models.Model):
datacenter = models.ForeignKey('DataCenter', on_delete=models.CASCADE)
}}}

Then I have decided to rename it into "Datacenter" so I was refactored my
code and call the "makemigrations" command. But no migration file has
created and it was obvious because model names are lowercased in the
database schema.
after a while, I have added this model

{{{
#!python
class Package(models.Model):
datacenters = models.ManyToManyField('Datacenter')
}}}

after creating that model every time I call the "makemigrations" command,
the same alter migration has been created.

{{{
#!python
migrations.AlterField(
model_name='package',
name='datacenters',
field=models.ManyToManyField(related_name='packages',
to='operations.Datacenter',
verbose_name='datacenters'),
),
}}}

after hours of debugging, I found that in the MigrationLoader's graph, the
model name is "DataCenter" because no "RenameModel" migration is even
created. then in the "deconstruct" of the M2M field unlike the ForiegnKey
field, the "to" attribute is set from "_meta.label" instead of
"_meta.label_lower".
and that causes a false change detection in "MigrationAutodetector" every
time.

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

Django

unread,
Sep 20, 2021, 5:41:32 AM9/20/21
to django-...@googlegroups.com
#33119: Change casing of a model's name referenced by ManyToManyField generates
unnecessary migrations.
-------------------------------------+-------------------------------------
Reporter: AliGhotbizadeh | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
M2M,RenameModel,deconstruct | Unreviewed
Has patch: 0 | Needs documentation: 0

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

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


Comment:

Thanks for the report, it was fixed in
aa4acc164d1247c0de515c959f7b09648b57dc42 (Django 4.0+).

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

Django

unread,
Sep 20, 2021, 6:31:26 AM9/20/21
to django-...@googlegroups.com
#33119: Change casing of a model's name referenced by ManyToManyField generates
unnecessary migrations.
-------------------------------------+-------------------------------------
Reporter: AliGhotbizadeh | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
M2M,RenameModel,deconstruct | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"b8f3a3ad54b05b83774716483afac7d0b9535fb4" b8f3a3a]:
{{{
#!CommitTicketReference repository=""
revision="b8f3a3ad54b05b83774716483afac7d0b9535fb4"
Refs #33119 -- Added tests for changing model name case referenced by
ManyToManyField.

Fixed in aa4acc164d1247c0de515c959f7b09648b57dc42.
}}}

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

Reply all
Reply to author
Forward
0 new messages