11"""
22Rename 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"""
77from 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