{{{
#!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.
* 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>
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>