* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
A regression test:
{{{#!diff
diff --git a/tests/migrations/test_operations.py
b/tests/migrations/test_operations.py
index d4fc3e855a..6366ccd667 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -2306,6 +2306,46 @@ class OperationTests(OperationTestBase):
operation.database_forwards(app_label, editor, new_state,
project_state)
self.assertColumnExists(rider_table, "pony_id")
+ def test_alter_field_foreignobject_noop(self):
+ app_label = "test_alflfo_noop"
+ project_state = self.set_up_test_model(app_label)
+ project_state = self.apply_operations(
+ app_label,
+ project_state,
+ [
+ migrations.CreateModel(
+ "Rider",
+ fields=[
+ ("pony_id", models.IntegerField()),
+ (
+ "pony",
+ models.ForeignObject(
+ f"{app_label}.Pony",
+ models.CASCADE,
+ from_fields=("pony_id",),
+ to_fields=("id",),
+ ),
+ ),
+ ],
+ ),
+ ],
+ )
+ operation = migrations.AlterField(
+ "Rider",
+ "pony",
+ models.ForeignObject(
+ f"{app_label}.Pony",
+ models.CASCADE,
+ from_fields=("pony_id",),
+ to_fields=("id",),
+ null=True,
+ ),
+ )
+ new_state = project_state.clone()
+ operation.state_forwards(app_label, new_state)
+ with self.assertNumQueries(0), connection.schema_editor() as
editor:
+ operation.database_forwards(app_label, editor, project_state,
new_state)
+
@skipUnlessDBFeature("supports_comments")
def test_alter_model_table_comment(self):
app_label = "test_almotaco"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:13>
Comment (by puc_dong):
Replying to [comment:13 Mariusz Felisiak]:
I realized that there will be a default exclude behavior, and there are 6
queries that will be executed in database setup, so I modified the use
case, and the 6 queries were not written directly.
This is my modification:https://github.com/django/django/pull/17240
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:14>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:15>
* owner: nobody => puc_dong
* status: new => assigned
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:16>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"71820c9f91a70076526e2f526236fc4172d92fea" 71820c9f]:
{{{
#!CommitTicketReference repository=""
revision="71820c9f91a70076526e2f526236fc4172d92fea"
Fixed #34820 -- Fixed migrations crash when changing a ForeignObject
field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34820#comment:17>