summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSamriddha9619 <sumitkumartripathi0@gmail.com>2025-09-23 01:27:30 +0530
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-09-29 09:00:19 +0200
commit6f3813e4b6e3db7fa3cc612c78f898142468bca9 (patch)
treedc5a3f646017f936ba34e2ef8122672a6d1d94fe /docs
parent10a2d3b837c5d8c1ac0cabd399ad7edcc66bfa8e (diff)
[5.2.x] Fixed #35877, Refs #36128 -- Documented unique constraint when migrating a m2m field to use a through model.
Backport of daba609a9bdc7a97bcf327c7ba0a5f7b3540b46e from main.
Diffstat (limited to 'docs')
-rw-r--r--docs/howto/writing-migrations.txt10
1 files changed, 9 insertions, 1 deletions
diff --git a/docs/howto/writing-migrations.txt b/docs/howto/writing-migrations.txt
index 2c52eccbad..34052805bc 100644
--- a/docs/howto/writing-migrations.txt
+++ b/docs/howto/writing-migrations.txt
@@ -334,7 +334,7 @@ model, the default migration will delete the existing table and create a new
one, losing the existing relations. To avoid this, you can use
:class:`.SeparateDatabaseAndState` to rename the existing table to the new
table name while telling the migration autodetector that the new model has
-been created. You can check the existing table name through
+been created. You can check the existing table name and constraint name through
:djadmin:`sqlmigrate` or :djadmin:`dbshell`. You can check the new table name
with the through model's ``_meta.db_table`` property. Your new ``through``
model should use the same names for the ``ForeignKey``\s as Django did. Also if
@@ -392,6 +392,14 @@ For example, if we had a ``Book`` model with a ``ManyToManyField`` linking to
),
),
],
+ options={
+ "constraints": [
+ models.UniqueConstraint(
+ fields=["author", "book"],
+ name="unique_author_book",
+ )
+ ],
+ },
),
migrations.AlterField(
model_name="book",