I accidentally deleted the admin (uid = 1) user in Drupal 9.x. Here's how you can re-create it:
- Generate new user:
drush user:create admin --password="qwerty" --mail="[email protected]"
drush user:role:add "administrator" admin
- Retrieve the UID of the user:
drush user:information admin
- Change the information in the database to using
drush sqlc
and executing the following commands (replacingXXX
with the uid of the newly created user)
-- Change UID 184027 -> 1 in users table
update users_field_data set uid = 1 where uid = XXX;
update users set uid = 1 where uid = XXX;
update users_data set uid = 1 where uid = XXX;
-- Change role
update user__roles set entity_id = 1 where entity_id = XXX;