mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Fixed #34824 -- Prevented unnecessary AlterField when ForeignObject.from_fields/to_fields is not a tuple.
This commit is contained in:
parent
369b498219
commit
938170008e
@ -1157,6 +1157,9 @@ class MigrationAutodetector:
|
|||||||
for to_field in new_field.to_fields
|
for to_field in new_field.to_fields
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
if old_from_fields := getattr(old_field, "from_fields", None):
|
||||||
|
old_field.from_fields = tuple(old_from_fields)
|
||||||
|
old_field.to_fields = tuple(old_field.to_fields)
|
||||||
dependencies.extend(
|
dependencies.extend(
|
||||||
self._get_dependencies_for_foreign_key(
|
self._get_dependencies_for_foreign_key(
|
||||||
app_label,
|
app_label,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import copy
|
||||||
import functools
|
import functools
|
||||||
import re
|
import re
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@ -1627,6 +1628,37 @@ class AutodetectorTests(BaseAutodetectorTests):
|
|||||||
changes, "app", 0, 0, old_name="field", new_name="renamed_field"
|
changes, "app", 0, 0, old_name="field", new_name="renamed_field"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_foreign_object_from_to_fields_list(self):
|
||||||
|
author_state = ModelState(
|
||||||
|
"app",
|
||||||
|
"Author",
|
||||||
|
[("id", models.AutoField(primary_key=True))],
|
||||||
|
)
|
||||||
|
book_state = ModelState(
|
||||||
|
"app",
|
||||||
|
"Book",
|
||||||
|
[
|
||||||
|
("id", models.AutoField(primary_key=True)),
|
||||||
|
("name", models.CharField()),
|
||||||
|
("author_id", models.IntegerField()),
|
||||||
|
(
|
||||||
|
"author",
|
||||||
|
models.ForeignObject(
|
||||||
|
"app.Author",
|
||||||
|
models.CASCADE,
|
||||||
|
from_fields=["author_id"],
|
||||||
|
to_fields=["id"],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
book_state_copy = copy.deepcopy(book_state)
|
||||||
|
changes = self.get_changes(
|
||||||
|
[author_state, book_state],
|
||||||
|
[author_state, book_state_copy],
|
||||||
|
)
|
||||||
|
self.assertEqual(changes, {})
|
||||||
|
|
||||||
def test_rename_foreign_object_fields(self):
|
def test_rename_foreign_object_fields(self):
|
||||||
fields = ("first", "second")
|
fields = ("first", "second")
|
||||||
renamed_fields = ("first_renamed", "second_renamed")
|
renamed_fields = ("first_renamed", "second_renamed")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user