#33953: RenameModel breaking change in 4.1 with ManyToManyField
------------------------------------------+-----------------------------
               Reporter:  Timothy Thomas  |          Owner:  nobody
                   Type:  Uncategorized   |         Status:  new
              Component:  Migrations      |        Version:  4.1
               Severity:  Normal          |       Keywords:  RenameModel
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+-----------------------------
 Steps:
 1) Create model with a ManyToManyField and a db_table in the Meta.
 2) Rename model and keep db_table the same as before

 The generated db schema generated from generating migrations would change
 the columns on the ManyToMany relationship table to match the model name.
 This matched the generated sql for interacting with this model as well.

 It is possible the db_table not changing is not required.

 Example:
 {{{
 class Publication(models.Model):
     title = models.CharField(max_length=30)

 class Article(models.Model):
     class Meta:
         db_table = "article"

     headline = models.CharField(max_length=100)
     publications = models.ManyToManyField(Publication)
 }}}

 Changed to:
 {{{
 class OtherArticle(models.Model):
     class Meta:
         db_table = "article"

     headline = models.CharField(max_length=100)
     publications = models.ManyToManyField(Publication)
 }}}

 with the corresponding migration:
 {{{
     operations = [
         migrations.RenameModel(
             old_name="Article",
             new_name="OtherArticle",
         ),
     ]
 }}}


 Previous behavior (4.0.6):
 The corresponding (functional) SQL gets generated:
 {{{
 'SELECT COUNT(*) AS "__count" FROM "publication" INNER JOIN
 "article_publications" ON ("article"."id" =
 "article_publications"."publication_id") WHERE
 "article_publications"."otherarticle_id" = %s'
 }}}

 Current behavior (4.1):
 **The same SQL gets generated but fails**. The schema that is now
 generated from running the same set of migrations on a fresh db would
 require:
 {{{
 'SELECT COUNT(*) AS "__count" FROM "publication" INNER JOIN
 "article_publications" ON ("article"."id" =
 "article_publications"."publication_id") WHERE
 "article_publications"."article_id" = %s'
 }}}
 as the column now matches the old model name. However, running that SQL
 would fail against our existing DB as it has ended up in a state that does
 not match the behavior of the existing migrations in the current version.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33953>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070182cc6262a2-46b86f69-5d43-46f9-9a34-064e9dc7a8d0-000000%40eu-central-1.amazonses.com.

Reply via email to