#35877: Documentation on "Changing a ManyToManyField to use a through model" 
does
not respect database index
-----------------------+-----------------------------------------
     Reporter:  robwa  |                     Type:  Bug
       Status:  new    |                Component:  Documentation
      Version:         |                 Severity:  Normal
     Keywords:         |             Triage Stage:  Unreviewed
    Has patch:  0      |      Needs documentation:  0
  Needs tests:  0      |  Patch needs improvement:  0
Easy pickings:  0      |                    UI/UX:  0
-----------------------+-----------------------------------------
 When creating a `manytomany` field with an implicit `through` table, a
 unique index is created on the database side for the `through` table for
 the two foreign keys. This fact is not respected in the documentation on
 [https://docs.djangoproject.com/en/dev/howto/writing-
 migrations/#changing-a-manytomanyfield-to-use-a-through-model Changing a
 ManyToManyField to use a through model]. When using the proposed code,
 Django loses track of the index.

 The addition of a simple options statement in the migration may be
 sufficient:


 {{{
     // ...
     operations = [
         migrations.CreateModel(
             name="AuthorBook",
             // ...
             options={
                 "unique_together": {("author", "book")},
             },
         ),
     ]
 }}}


 I have not been able to check comprehensively how different database
 systems behave when interacting with Django and in the context of renaming
 the table. SQLite retains the index, but it is not renamed. In the case of
 PostgreSQL, there were later bugs in an implementation that were difficult
 to find.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35877>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070192dcfac475-a877c060-b77e-494a-b0d1-e702397acfaa-000000%40eu-central-1.amazonses.com.

Reply via email to