diff --git a/common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py b/common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py new file mode 100644 index 000000000000..3f57f3305292 --- /dev/null +++ b/common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py @@ -0,0 +1,26 @@ +# rm user foreign key db constraint to avoid deadlocks when deleting users. + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('student', '0049_manualenrollmentaudit_statetransition_typo'), + ] + + operations = [ + migrations.AlterField( + model_name='courseenrollment', + name='user', + field=models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='courseenrollmentallowed', + name='user', + field=models.ForeignKey(blank=True, db_constraint=False, help_text="First user which enrolled in the specified course through the specified e-mail. Once set, it won't change.", null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/common/djangoapps/student/models/course_enrollment.py b/common/djangoapps/student/models/course_enrollment.py index cbf257b77f46..1c3b35dc104a 100644 --- a/common/djangoapps/student/models/course_enrollment.py +++ b/common/djangoapps/student/models/course_enrollment.py @@ -307,7 +307,7 @@ class CourseEnrollment(models.Model): """ MODEL_TAGS = ['course', 'is_active', 'mode'] - user = models.ForeignKey(User, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.CASCADE, db_constraint=False) course = models.ForeignKey( CourseOverview, @@ -1611,6 +1611,7 @@ class CourseEnrollmentAllowed(DeletableByUserValue, models.Model): help_text="First user which enrolled in the specified course through the specified e-mail. " "Once set, it won't change.", on_delete=models.CASCADE, + db_constraint=False, ) created = models.DateTimeField(auto_now_add=True, null=True, db_index=True)