diff options
| author | donghao <is_simple@163.com> | 2023-09-09 21:39:43 +0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-11 08:46:43 +0200 |
| commit | 938170008ea48dff8f89b0839998a1eec939ddf4 (patch) | |
| tree | c6ce582aa315f6b8f13df1fb2a32880452c27552 /tests | |
| parent | 369b498219be791ebec8233208f08f07621b8359 (diff) | |
Fixed #34824 -- Prevented unnecessary AlterField when ForeignObject.from_fields/to_fields is not a tuple.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 4c91659ca8..85674e552a 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -1,3 +1,4 @@ +import copy import functools import re from unittest import mock @@ -1627,6 +1628,37 @@ class AutodetectorTests(BaseAutodetectorTests): 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): fields = ("first", "second") renamed_fields = ("first_renamed", "second_renamed") |
