The Users table will be the single source of truth of the user accounts that are active / inactive in the Mattermost instance. Since you mentioned that the user is still appearing in the team (which I believe the user was a member of originally), I want to know if this is merely a old data / cache issue of the Mattermost desktop / web / mobile app.
As the user is not appearing in the system console and database, can you please perform the following steps to verify if the same user is still appearing after that?
Desktop App
Log in to the desktop app.
Click on View > Clear Cache & Reload.
Switch between channels and use the channel switcher to search for the user.
Check through direct message / channels / group messages to verify that the user is still present or not.
Web App
Using an incognito / private mode of the web browser, log in to your Mattermost account.
Verify if the user is still appearing when you search for the account via the channel switcher (Command + K for Mac OS OR Ctrl + K or Windows).
Perform the same process similar to the desktop app above.
Mobile App
Log in to your mobile app using your credentials
Navigate to Settings > Advanced Settings > Delete Documents & Data and observe the client reload itself and search for the ghost user again.
We are not detecting this using any of the above apps
We are detecting it using the API directly - there is no cache involved.
If I had access to the database, I could check, but I would guess that the team members table has a record in it for a user who doesn’t exist in the users table.
Is there a foreign key relationship defined for this field?
Based on the SQL query that I have used, I could not find any foreign key relationship in the Users table:
mysql> SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA. KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = 'mattermost' AND REFERENCED_TABLE_NAME = 'Users';
Empty set (0.02 sec)
Have you had any luck with the accessing the database to confirm the existence of the user and compare it with the output that you are seeing from the API?