Skip to content

Commit bcb3f6b

Browse files
Merge pull request #36823 from openedx/iamsobanjaved/fix-csmh-index-migration
[DO NOT MERGE – Needs Staging Verification] fix!: Update the migration to have one Index on student_module_id
2 parents be09d1c + 97a847d commit bcb3f6b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by Django 4.2.20 on 2025-05-15 03:30
22

3-
from django.db import migrations
3+
from django.db import migrations, models
4+
import django.db.models.deletion
45

56

67
class Migration(migrations.Migration):
@@ -10,9 +11,26 @@ class Migration(migrations.Migration):
1011
]
1112

1213
operations = [
13-
migrations.RenameIndex(
14+
migrations.AlterField(
1415
model_name='studentmodulehistoryextended',
15-
new_name='student_module_idx',
16-
old_fields=('student_module',),
16+
name='student_module',
17+
field=models.ForeignKey(db_constraint=False, db_index=False, on_delete=django.db.models.deletion.DO_NOTHING, to='courseware.studentmodule'),
18+
),
19+
# This SeparateDatabaseAndState operation updates the state to match the model.
20+
# database_operations is left empty because the indexes were already dropped
21+
# by the previous operation in the database.
22+
migrations.SeparateDatabaseAndState(
23+
database_operations=[],
24+
state_operations=[
25+
migrations.AlterIndexTogether(
26+
name='studentmodulehistoryextended',
27+
index_together=set(),
28+
),
29+
],
30+
),
31+
# Adds back the index on 'student_module' to ensure there is a single index on this field.
32+
migrations.AddIndex(
33+
model_name='studentmodulehistoryextended',
34+
index=models.Index(fields=['student_module'], name='student_module_idx'),
1735
),
1836
]

lms/djangoapps/coursewarehistoryextended/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Meta:
4242

4343
id = UnsignedBigIntAutoField(primary_key=True) # pylint: disable=invalid-name
4444

45-
student_module = models.ForeignKey(StudentModule, db_index=True, db_constraint=False, on_delete=models.DO_NOTHING)
45+
student_module = models.ForeignKey(StudentModule, db_index=False, db_constraint=False, on_delete=models.DO_NOTHING)
4646

4747
@receiver(post_save, sender=StudentModule)
4848
def save_history(sender, instance, **kwargs): # pylint: disable=no-self-argument, unused-argument

0 commit comments

Comments
 (0)