kit
(Kit)
September 19, 2022, 4:39am
1
I was able to use this command to remove a user:
tutor local run lms ./manage.py lms manage_user --remove <user_name> <user_email>
When I tried it with a second user, I got an error:
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`))')
Error: Command failed with status 1: docker-compose -f /home/kit/.local/share/tutor/env/local/docker-compose.yml -f /home/kit/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/kit/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local run --rm lms ./manage.py lms manage_user --remove username email
What I’ve tried:
Restarting the server and re-running the command leads to the same error.
tutor version 14.0.4
TonyH
(Tony H)
September 19, 2022, 5:57am
2
From our experience, we couldn’t delete users with active course enrollments. Hopefully, that will solve the problem. It seems that I’ve had to search for the user references in other places, such as access tokens, to get it to release the user.
Also, try deleting the users in both places, in Django
and using manage_user
. It seems the one might work when the other option wouldn’t.
1 Like
ghassan
(Ghassan Maslamani)
September 19, 2022, 10:35am
3
For me when I ran into this error, I just followed what it said, i.e. I deleted the user from coursecreator table first (not sure if thats is the correct name of the table). And then tried to delete it again from User table. (Using Django/Python Shell)
2 Likes
lpm0073
(Lawrence McDaniel)
September 19, 2022, 5:47pm
4
If you have MySQL access then you can run this script to remove problematic user accounts: https://github.com/lpm0073/cookiecutter-openedx-devops/scripts/sql/delete-user.sql
1 Like
kit
(Kit)
September 20, 2022, 5:01am
5
ghassan:
For me when I ran into this error, I just followed what it said, i.e. I deleted the user from coursecreator table first (not sure if thats is the correct name of the table). And then tried to delete it again from User table. (Using Django/Python Shell)
Perfect.
For future reference, here’s how I did it:
Get a mysql console
Find the user ID of the user you’re removing: select id, username, email, is_active from auth_user;
[Optional] Find out which row of the course_creators_coursecreator table needs to be deleted: select * from course_creators_coursecreator;
Delete that user: delete from course_creators_coursecreator where user_id = [ID];
[Optional] Verify that this course_creator row has been removed select * from course_creators_coursecreator;
Exit the mysql console
Re-run the original tutor command: tutor local run lms ./manage.py lms manage_user --remove <user_name> <user_email>
1 Like