mirror of
https://github.com/django/django.git
synced 2025-10-09 14:59:24 +00:00
[6.0.x] Fixed #35877, Refs #36128 -- Documented unique constraint when migrating a m2m field to use a through model.
Backport of daba609a9bdc7a97bcf327c7ba0a5f7b3540b46e from main.
This commit is contained in:
parent
f8e91d0104
commit
956455dc8a
@ -336,7 +336,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
|
one, losing the existing relations. To avoid this, you can use
|
||||||
:class:`.SeparateDatabaseAndState` to rename the existing table to the new
|
:class:`.SeparateDatabaseAndState` to rename the existing table to the new
|
||||||
table name while telling the migration autodetector that the new model has
|
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
|
:djadmin:`sqlmigrate` or :djadmin:`dbshell`. You can check the new table name
|
||||||
with the through model's ``_meta.db_table`` property. Your new ``through``
|
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
|
model should use the same names for the ``ForeignKey``\s as Django did. Also if
|
||||||
@ -394,6 +394,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(
|
migrations.AlterField(
|
||||||
model_name="book",
|
model_name="book",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user