#33953: RenameModel breaking change in 4.1 with ManyToManyField
---------------------------------+------------------------------------
     Reporter:  Timothy Thomas   |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Migrations       |                  Version:  4.1
     Severity:  Release blocker  |               Resolution:
     Keywords:  RenameModel      |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------
Changes (by Carlton Gibson):

 * type:  Uncategorized => Bug
 * severity:  Normal => Release blocker
 * stage:  Unreviewed => Accepted


Comment:

 This was changed in afeafd6036616bac8263d762c1610f22241c0187 for  #33201,
 which made RenameModel a no-op where the `db_table` is specified and
 unchanged.

 Something looks amiss though.

 With the models you provide, creating migrations for `Article` and then
 the renamed `OtherArticle`, I see the following in the shell:


 {{{
 >>> from app.models import Publication, OtherArticle
 >>> p = Publication.objects.create(title="Testing")
 >>> a = OtherArticle.objects.create(headline="Will this work?")
 >>> a.publications.add(p)
 Traceback (most recent call last):
   File
 "/Users/carlton/Projects/Django/django/django/db/backends/utils.py", line
 89, in _execute
     return self.cursor.execute(sql, params)
   File
 "/Users/carlton/Projects/Django/django/django/db/backends/sqlite3/base.py",
 line 369, in execute
     return Database.Cursor.execute(self, query, params)
 sqlite3.OperationalError: table article_publications has no column named
 otherarticle_id

 The above exception was the direct cause of the following exception:

 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File
 
"/Users/carlton/Projects/Django/django/django/db/models/fields/related_descriptors.py",
 line 1114, in add
     self._add_items(

 ...[snip]...

   File
 "/Users/carlton/Projects/Django/django/django/db/backends/utils.py", line
 89, in _execute
     return self.cursor.execute(sql, params)
   File
 "/Users/carlton/Projects/Django/django/django/db/backends/sqlite3/base.py",
 line 369, in execute
     return Database.Cursor.execute(self, query, params)
 django.db.utils.OperationalError: table article_publications has no column
 named otherarticle_id
 >>> ^D
 }}}


 Relevant DB schema:

 {{{
 sqlite> .tables
 app_publication             auth_user_groups
 article                     auth_user_user_permissions
 article_publications        django_admin_log
 auth_group                  django_content_type
 auth_group_permissions      django_migrations
 auth_permission             django_session
 auth_user

 sqlite> .schema article
 CREATE TABLE IF NOT EXISTS "article" ("id" integer NOT NULL PRIMARY KEY
 AUTOINCREMENT, "headline" varchar(100) NOT NULL);

 sqlite> .schema article_publications
 CREATE TABLE IF NOT EXISTS "article_publications" ("id" integer NOT NULL
 PRIMARY KEY AUTOINCREMENT, "article_id" bigint NOT NULL REFERENCES
 "article" ("id") DEFERRABLE INITIALLY DEFERRED, "publication_id" bigint
 NOT NULL REFERENCES "app_publication" ("id") DEFERRABLE INITIALLY
 DEFERRED);
 CREATE UNIQUE INDEX
 "article_publications_article_id_publication_id_8dd463d8_uniq" ON
 "article_publications" ("article_id", "publication_id");
 CREATE INDEX "article_publications_article_id_f32c80b0" ON
 "article_publications" ("article_id");
 CREATE INDEX "article_publications_publication_id_7425f904" ON
 "article_publications" ("publication_id");
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33953#comment:1>
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/01070182ced7bef2-4a04933c-075c-42b9-92a8-fa1e47f5a0d5-000000%40eu-central-1.amazonses.com.

Reply via email to