#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.b701ec930227554ab648538e28c50c44%40djangoproject.com.

Reply via email to