From 84fe8020e4cd8843b8ca4468c2e618eca78de7c4 Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Tue, 23 Jun 2026 16:21:25 -0500 Subject: [PATCH 1/2] feat!: rm user db_constraing in CourseEnrollment (cherry picked from commit a022b690a6b779d82592b6b1844d970d4fbec39b) --- ...nrollment_rm_user_foreign_db_constraint.py | 26 +++++++++++++++++++ .../student/models/course_enrollment.py | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py diff --git a/common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py b/common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py new file mode 100644 index 000000000000..ba9f0b765654 --- /dev/null +++ b/common/djangoapps/student/migrations/0047_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', '0046_alter_userprofile_phone_number'), + ] + + 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) From b6aa926694ee50db20d04a28d74312128524679d Mon Sep 17 00:00:00 2001 From: Johan Castiblanco Date: Wed, 24 Jun 2026 16:05:54 -0500 Subject: [PATCH 2/2] feat: reorder the migration position --- ...py => 0050_coursenrollment_rm_user_foreign_db_constraint.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename common/djangoapps/student/migrations/{0047_coursenrollment_rm_user_foreign_db_constraint.py => 0050_coursenrollment_rm_user_foreign_db_constraint.py} (93%) diff --git a/common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py b/common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py similarity index 93% rename from common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py rename to common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py index ba9f0b765654..3f57f3305292 100644 --- a/common/djangoapps/student/migrations/0047_coursenrollment_rm_user_foreign_db_constraint.py +++ b/common/djangoapps/student/migrations/0050_coursenrollment_rm_user_foreign_db_constraint.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('student', '0046_alter_userprofile_phone_number'), + ('student', '0049_manualenrollmentaudit_statetransition_typo'), ] operations = [