Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #34820 -- Fixed migrations crash when changing a ForeignObject field. #17240

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ answer newbie questions, and generally made Django that much better:
Hang Park <hangpark@kaist.ac.kr>
Hannes Ljungberg <hannes.ljungberg@gmail.com>
Hannes Struß <x@hannesstruss.de>
Hao Dong <https://github.com/RelaxedDong>
Harm Geerts <hgeerts@gmail.com>
Hasan Ramezani <hasan.r67@gmail.com>
Hawkeye
Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/base/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ def _field_indexes_sql(self, model, field):
return output

def _field_should_be_altered(self, old_field, new_field, ignore=None):
if not old_field.concrete and not new_field.concrete:
return False
ignore = ignore or set()
_, old_path, old_args, old_kwargs = old_field.deconstruct()
_, new_path, new_args, new_kwargs = new_field.deconstruct()
Expand Down
46 changes: 46 additions & 0 deletions tests/migrations/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,52 @@ def test_alter_field_add_db_column_noop(self):
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 (
CaptureQueriesContext(connection) as ctx,
connection.schema_editor() as editor,
):
operation.database_forwards(app_label, editor, project_state, new_state)
self.assertIs(
any("ALTER" in query["sql"] for query in ctx.captured_queries), False
)

@skipUnlessDBFeature("supports_comments")
def test_alter_model_table_comment(self):
app_label = "test_almotaco"
Expand Down