Unfortunately deleted all the users

Hi Goodday,

unfortunately I deleted the all the users along with administrator using query. Now I am unable to use is there any solution to get the administrator or create new user for admin.

Thanks & Regards
krishna

Go to terminal and run bench --site site_name console

In the console run the following commands -

doc = frappe.get_doc({'doctype':'User', 'name':'Administrator', 'first_name':'Administrator', 'email':'admin@example.com', 'enabled':1, "is_admin": 1, 'roles': [{'role': 'Administrator'})

doc.insert()
frappe.db.commit()
exit

After exiting from the console, in the terminal run bench set-admin-password any_password

2 Likes

do you not have backups? could you not just grab the table from the gzipped sql file?

I will check and let u know…tq very much @Zlash65

I am doing in local bench presently I am not using any backups

check the contents of /frappe-bench/sites/site_name/private/backups

If you have any files there (Most likely). You can restore your site to the most recent backup

To restore backups, refer to https://github.com/frappe/erpnext/wiki/Restoring-From-ERPNext-Backup