diff --git a/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py b/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py index c39e2410b5..9a860e9206 100644 --- a/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py +++ b/lms/djangoapps/coursewarehistoryextended/migrations/0003_rename_studentmodulehistoryextended_student_module_student_module_idx.py @@ -1,6 +1,7 @@ # Generated by Django 4.2.20 on 2025-05-15 03:30 -from django.db import migrations +from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -10,9 +11,26 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RenameIndex( + migrations.AlterField( model_name='studentmodulehistoryextended', - new_name='student_module_idx', - old_fields=('student_module',), + name='student_module', + field=models.ForeignKey(db_constraint=False, db_index=False, on_delete=django.db.models.deletion.DO_NOTHING, to='courseware.studentmodule'), + ), + # This SeparateDatabaseAndState operation updates the state to match the model. + # database_operations is left empty because the indexes were already dropped + # by the previous operation in the database. + migrations.SeparateDatabaseAndState( + database_operations=[], + state_operations=[ + migrations.AlterIndexTogether( + name='studentmodulehistoryextended', + index_together=set(), + ), + ], + ), + # Adds back the index on 'student_module' to ensure there is a single index on this field. + migrations.AddIndex( + model_name='studentmodulehistoryextended', + index=models.Index(fields=['student_module'], name='student_module_idx'), ), ] diff --git a/lms/djangoapps/coursewarehistoryextended/models.py b/lms/djangoapps/coursewarehistoryextended/models.py index d9e2d54cca..0ba1c22e06 100644 --- a/lms/djangoapps/coursewarehistoryextended/models.py +++ b/lms/djangoapps/coursewarehistoryextended/models.py @@ -42,7 +42,7 @@ class StudentModuleHistoryExtended(BaseStudentModuleHistory): id = UnsignedBigIntAutoField(primary_key=True) # pylint: disable=invalid-name - student_module = models.ForeignKey(StudentModule, db_index=True, db_constraint=False, on_delete=models.DO_NOTHING) + student_module = models.ForeignKey(StudentModule, db_index=False, db_constraint=False, on_delete=models.DO_NOTHING) @receiver(post_save, sender=StudentModule) def save_history(sender, instance, **kwargs): # pylint: disable=no-self-argument, unused-argument