Deleted user with rails console u.delete -> email still "taken"

AI-generated summary

A user (Wille) deleted an admin account using the rails console but is unable to reuse the associated email address. They suspect this might be a bug.

IAmGav suggests using the data explorer plugin to find and delete the email record from the relevant table. However, Wille points out that this approach would require manual queries for multiple tables.

simon believes this might not be a bug and provides console commands to search for the email record and associated user. If the user is deleted, simon recommends destroying the email record, but only after creating a site backup.

jomaxro suggests using the UserDestroyer method to delete users from the console, as described in the deleting users in rails console guide.

So the old e-mail I had assigned to my admin account no longer existed after changing domains, so I wanted to change the e-mail address but couldn’t because it requires a verification to the old e-mail.

Long story short I did a bunch of things, changed some e-mails, created another admin account, and deleted the second admin account using the console, but now I can’t reuse the email I had assigned to the second admin account.

Not sure whether to put this under support or bugs.
To be honest I have a backup I could try to use, but before doing that, is this a bug? Any way to fix this without a full reset / restoring from a backup?

install the data explorer plugin and then you can check which table still has your email that you want to delete

You’d still need to know which table(s) to look/delete from, unless you’re proposing that I should manually create 100+ uniquely crafted queries for 100+ different tables with different schemas.

Would appreciate if someone could recategorize this post under bugs.

It seems likely that this is not a bug. It depends how you deleted the user from the console.

From the console, try searching for:

UserEmail.where(email: '<your_deleted_users_email>')

If that gives you a result, try searching for the user with the user_id that was returned:

User.find_by(id: <email_record_id>)

My guess is that no user will be returned because the email belonged to the user you deleted. If that is the case, it should be safe to call destroy! on the email record. Before trying this, be sure that you have an up-to-date backup of your site.

If the email does belong to an existing user, do not delete the email record.

3 Likes

To delete a user from the console, use UserDestroyer. See Deleting Users in rails console - #2 by jomaxro.

Note to self, turn that into #howto:faq

5 Likes