1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #35595, #35962 -- Removed indexes and constraints before fields in migrations.

This commit is contained in:
wookkl
2025-06-18 01:34:10 +09:00
committed by Sarah Boyce
parent a388287692
commit 29f5e1e97d
2 changed files with 132 additions and 1 deletions

View File

@@ -2978,6 +2978,92 @@ class AutodetectorTests(BaseAutodetectorTests):
changes, "otherapp", 0, 0, model_name="book", name="book_title_author_idx"
)
def test_remove_field_with_model_options(self):
before_state = [
ModelState("testapp", "Animal", []),
ModelState(
"testapp",
"Dog",
fields=[
("name", models.CharField(max_length=100)),
(
"animal",
models.ForeignKey("testapp.Animal", on_delete=models.CASCADE),
),
],
options={
"indexes": [
models.Index(fields=("animal", "name"), name="animal_name_idx")
],
"constraints": [
models.UniqueConstraint(
fields=("animal", "name"), name="animal_name_idx"
),
],
},
),
]
changes = self.get_changes(before_state, [])
# Right number/type of migrations?
self.assertNumberMigrations(changes, "testapp", 1)
self.assertOperationTypes(
changes,
"testapp",
0,
[
"RemoveIndex",
"RemoveConstraint",
"RemoveField",
"DeleteModel",
"DeleteModel",
],
)
def test_remove_field_with_remove_index_or_constraint_dependency(self):
before_state = [
ModelState("testapp", "Category", []),
ModelState(
"testapp",
"Model",
fields=[
("date", models.DateField(auto_now=True)),
(
"category",
models.ForeignKey(
"testapp.Category", models.SET_NULL, null=True
),
),
],
options={
"constraints": [
models.UniqueConstraint(
fields=("date", "category"), name="unique_category_for_date"
),
]
},
),
]
changes = self.get_changes(
before_state,
[
ModelState(
"testapp",
"Model",
fields=[
("date", models.DateField(auto_now=True)),
],
),
],
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, "testapp", 1)
self.assertOperationTypes(
changes,
"testapp",
0,
["RemoveConstraint", "RemoveField", "DeleteModel"],
)
def test_rename_indexes(self):
book_renamed_indexes = ModelState(
"otherapp",