﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35877	"Documentation on ""Changing a ManyToManyField to use a through model"" does not respect database index"	robwa	Samriddha Kumar Tripathi	"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."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed		Adam Johnson Mariusz Felisiak	Ready for checkin	1	0	0	0	0	0
