If users have been deleted directly from the database enrolment information can be left behind can cause some issues in the future.
To remove user enrolment information for users that do not exist any longer. Please run the following SQL command.
Before doing so, please ensure you have taken a database backup before running this command - there is no going back.
DELETE FROM mdl_user_enrolments ue LEFT JOIN mdl_user u ON ue.userid = u.id WHERE u.id IS NULL