diff --git a/common/djangoapps/course_modes/migrations/0008_course_key_field_to_foreign_key.py b/common/djangoapps/course_modes/migrations/0008_course_key_field_to_foreign_key.py index 7b9ff2da41..ceb45dd0de 100644 --- a/common/djangoapps/course_modes/migrations/0008_course_key_field_to_foreign_key.py +++ b/common/djangoapps/course_modes/migrations/0008_course_key_field_to_foreign_key.py @@ -5,6 +5,16 @@ from django.db import migrations, models import openedx.core.djangoapps.xmodule_django.models +# This should only be used for migrations that have be verified to have a net-neutral sql +# change generated by Django +class NoSqlAlterField(migrations.AlterField): + def database_forwards(self, app_label, schema_editor, from_state, to_state): + return + + def database_backwards(self, app_label, schema_editor, from_state, to_state): + return + + class Migration(migrations.Migration): dependencies = [ @@ -32,7 +42,7 @@ class Migration(migrations.Migration): # name to above). # We deliberately leave db_constraint set to False because the column # isn't currently constrained - migrations.AlterField( + NoSqlAlterField( model_name='coursemode', name='course', field=models.ForeignKey(related_name='modes', db_constraint=False, default=None, to='course_overviews.CourseOverview'), diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index cd51903041..3fc66994e2 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -41,7 +41,12 @@ class CourseMode(models.Model): class Meta(object): app_label = "course_modes" - course = models.ForeignKey(CourseOverview, db_constraint=False, db_index=True, related_name='modes') + course = models.ForeignKey( + CourseOverview, + db_constraint=False, + db_index=True, + related_name='modes', + ) # Django sets the `course_id` property in __init__ with the value from the database # This pair of properties converts that into a proper CourseKey diff --git a/common/djangoapps/student/migrations/0011_course_key_field_to_foreign_key.py b/common/djangoapps/student/migrations/0011_course_key_field_to_foreign_key.py index c2ecc2cd40..1afbbc1345 100644 --- a/common/djangoapps/student/migrations/0011_course_key_field_to_foreign_key.py +++ b/common/djangoapps/student/migrations/0011_course_key_field_to_foreign_key.py @@ -6,6 +6,16 @@ import django.db.models.deletion import openedx.core.djangoapps.xmodule_django.models +# This should only be used for migrations that have be verified to have a net-neutral sql +# change generated by Django +class NoSqlAlterField(migrations.AlterField): + def database_forwards(self, app_label, schema_editor, from_state, to_state): + return + + def database_backwards(self, app_label, schema_editor, from_state, to_state): + return + + class Migration(migrations.Migration): dependencies = [ @@ -41,13 +51,13 @@ class Migration(migrations.Migration): # Alter the fields to make them ForeignKeys (leaving off the db_constraint so # that we don't create it at migration time). The db_column is left off because # it defaults to ${field_name}_id, which we pinned it to up above. - migrations.AlterField( + NoSqlAlterField( model_name='courseenrollment', name='course', field=models.ForeignKey(db_constraint=False, to='course_overviews.CourseOverview'), preserve_default=True, ), - migrations.AlterField( + NoSqlAlterField( model_name='historicalcourseenrollment', name='course', field=models.ForeignKey(related_name='+', on_delete=django.db.models.deletion.DO_NOTHING, db_constraint=False, blank=True, to='course_overviews.CourseOverview', null=True), diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 0ad0b544d1..580b00bd70 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -996,7 +996,10 @@ class CourseEnrollment(models.Model): user = models.ForeignKey(User) - course = models.ForeignKey(CourseOverview, db_constraint=False) + course = models.ForeignKey( + CourseOverview, + db_constraint=False, + ) @property def course_id(self):