﻿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
37034	Improve writing migrations how-to add through field on a ManyToManyField	Clifford Gama	Clifford Gama	"1. Inaccurate description of how Django handles this change: The section states that ""the default migration will delete the existing table and create a new one"". This is not accurate. Django [https://github.com/django/django/blob/d61f33f03b3177afdf1d76153014bad4107b1224/django/db/backends/base/schema.py#L894 refuses to apply a migration] when `through=` is added/changed on an existing `ManyToManyField`.

2. The through model example does not accurately reflect the database: The current example uses `on_delete=DO_NOTHING` and `models.UniqueConstraint`, whereas Django's auto-generated through tables use `CASCADE` and `unique_together`. In other words, future model states will not bear a correct representation of what's in the db.

3. The example can be simplified by setting `Meta.db_table` on the new through model to match the existing table name, eliminating the need for a `RunSQL` rename operation.

The section also suggests using `sqlmigrate` or `dbshell` to find the existing table name, which is indirect. The simplest approach is to inspect `field.through._meta.db_table` before modifying the field.

Incidentally for the case where db_table remains the same, #36803 may allow us to suggest a simpler alternative in the docs, one that does not need to use `SeparateDatabaseAndState`."	Bug	assigned	Documentation	dev	Normal		migrations, ManyToManyField, through	Adam Johnson	Unreviewed	0	0	0	0	0	0
