Deleting a user that has requested course creator

H,

I am attempting to delete a user using

tutor local run lms ./manage.py lms manage_user --remove USERNAME EMAIL

but it turns out that this user had requested (and got declined) course creator status. The deletion therefore fails with:

MySQLdb.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`openedx`.`course_creators_coursecreator`, CONSTRAINT `course_creators_coursecreator_user_id_e4da548d_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')
django.db.utils.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`openedx`.`course_creators_coursecreator`, CONSTRAINT `course_creators_coursecreator_user_id_e4da548d_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')

It seems that from the course_creatorsdjango app, I cannot delete entries, only modify them.

How can I actually delete this ?

@TyHob since you recently looked into course creator… would you have any advice here?

I don’t know of any way to delete from the audit table using any existing UI or script, we generally don’t recommend deleting users at all, but you should be able to delete that row with a horrible one liner like (note: untested, but should be close):

tutor local run lms ./manage.py lms shell -c "from django.contrib.auth import get_user_model; from course_creators.models import CourseCreator; User = get_user_model(); print(CourseCreator.objects.filter(user=User.objects.get(username='USERNAME')).delete())"

Then the manage_user --remove should work.

I get

ModuleNotFoundError: No module named 'course_creators'

Ok, the right syntax was:

tutor local run cms ./manage.py cms shell -c "from django.contrib.auth import get_user_model; from cms.djangoapps.course_creators.models import CourseCreator; User = get_user_model(); print(CourseCreator.objects.filter(user=User.objects.get(username='USERNAME')).delete())"