Skip to content

Commit b9d11db

Browse files
kdmccormickclaude
andcommitted
fix(squash): replace SeparateDatabaseAndState+RunSQL with plain AlterField
Django's schema editor correctly detects the column rename when db_column is dropped (old_field.column='_key' vs new_field.column='entity_ref'), so SeparateDatabaseAndState is unnecessary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4986446 commit b9d11db

1 file changed

Lines changed: 18 additions & 38 deletions

File tree

src/openedx_content/migrations/0011_rename_entity_key_and_package_key_to_refs.py

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Rename PublishableEntity.key -> entity_ref and LearningPackage.key -> package_ref.
33
4-
Both fields previously had db_column='_key'; this migration also renames the
5-
underlying DB columns to match the new field names.
4+
Both fields previously had db_column='_key'; the AlterField steps drop that
5+
override, which causes Django's schema editor to rename the DB column too.
66
"""
77
from django.db import migrations, models
88

@@ -31,25 +31,15 @@ class Migration(migrations.Migration):
3131
new_name='entity_ref',
3232
),
3333
# RenameField only changes the Django field name; the DB column is still
34-
# '_key' (set via db_column). Use SeparateDatabaseAndState to rename the
35-
# actual column and drop the db_column override from state.
36-
migrations.SeparateDatabaseAndState(
37-
state_operations=[
38-
migrations.AlterField(
39-
model_name='publishableentity',
40-
name='entity_ref',
41-
field=openedx_django_lib.fields.MultiCollationCharField(
42-
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
43-
max_length=500,
44-
),
45-
),
46-
],
47-
database_operations=[
48-
migrations.RunSQL(
49-
sql='ALTER TABLE openedx_content_publishableentity RENAME COLUMN _key TO entity_ref',
50-
reverse_sql='ALTER TABLE openedx_content_publishableentity RENAME COLUMN entity_ref TO _key',
51-
),
52-
],
34+
# '_key' (set via db_column). AlterField drops db_column, so Django sees
35+
# old column='_key' vs new column='entity_ref' and renames it.
36+
migrations.AlterField(
37+
model_name='publishableentity',
38+
name='entity_ref',
39+
field=openedx_django_lib.fields.MultiCollationCharField(
40+
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
41+
max_length=500,
42+
),
5343
),
5444
migrations.AddConstraint(
5545
model_name='publishableentity',
@@ -76,23 +66,13 @@ class Migration(migrations.Migration):
7666
old_name='key',
7767
new_name='package_ref',
7868
),
79-
migrations.SeparateDatabaseAndState(
80-
state_operations=[
81-
migrations.AlterField(
82-
model_name='learningpackage',
83-
name='package_ref',
84-
field=openedx_django_lib.fields.MultiCollationCharField(
85-
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
86-
max_length=500,
87-
),
88-
),
89-
],
90-
database_operations=[
91-
migrations.RunSQL(
92-
sql='ALTER TABLE openedx_content_learningpackage RENAME COLUMN _key TO package_ref',
93-
reverse_sql='ALTER TABLE openedx_content_learningpackage RENAME COLUMN package_ref TO _key',
94-
),
95-
],
69+
migrations.AlterField(
70+
model_name='learningpackage',
71+
name='package_ref',
72+
field=openedx_django_lib.fields.MultiCollationCharField(
73+
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
74+
max_length=500,
75+
),
9676
),
9777
migrations.AddConstraint(
9878
model_name='learningpackage',

0 commit comments

Comments
 (0)