# Reset Django Admin Password with manage.py Commands

> Reset a forgotten Django admin password using manage.py changepassword, createsuperuser, or direct database queries, with steps for each approach

**URL:** https://sentry.io/answers/how-to-reset-django-admin-password/

---

## The Problem

You've forgotten your password and/or username for the Django admin panel. How can you get access to the admin panel again?

## The Solution

The easiest way to reset your password is by using the Django `manage.py` script, which includes a `changepassword` command. For example, if you know that the username for the admin account is `admin`, you can reset it by running the following code:

```bash
python3 manage.py changepassword admin
```

You'll be prompted for a new password and after entering it twice, you'll be able to log into the admin panel through the UI using that password.

```bash
Changing password for user '<admin@example.com>'
Password:
Password (again):
Password changed successfully for user '<admin@example.com>'
```

### Alternative options

There are a few other ways of resetting a password or finding a lost admin username that may be easier for you depending on your exact setup. You can reset a password at different levels of the Django application, including:

* Using the Django admin panel (though only if you have access to another admin account).
* Using the command line interface through the `manage.py` script.
* Directly in the underlying database.

Generally, it's safest and easiest to use the UI if you can and the command line script if necessary. You should avoid editing the database directly unless you know exactly what you are doing and have no other option, as it's easy to break or corrupt your database by running database queries directly.

#### Using the admin panel

If you have access to another Django admin account, you can see all usernames and reset the password for the admin account you've forgotten by going to the "Users" page and using the reset password form.

Alternatively, you can promote another user account that you do know the credentials for to "Superuser status".

#### Using the `manage.py` script

You can use the `changepassword` command as demonstrated earlier. If you can't use remember the username either, you can create a new admin account using the `createsuperuser` command. Run:

```shell
python3 manage.py createsuperuser
```

You will be prompted for a new username and password for a new admin account. You can then use the new admin account to find the username and/or reset the password of the existing account through the admin panel, as above.

#### Using the database directly

If you just want to be reminded of your admin account's username and you can access the database directly, run:

```SQL
SELECT username, email from users_customuser WHERE is_superuser;
```

This will return a list of all existing administrators. Your users might be stored in a different table, in which case you can run one of the following commands (depending on which database you're using), to see all tables, and then substitute the correct table name in the above query:

```
\dt;  # postgres
.tables # sqlite
SHOW TABLES;  # mysql
```

#### Promoting a user to admin in the database

**NOTE: this is a potentially destructive operation. Proceed with caution.**

If you want to promote a normal user to admin and you only have access to the database, you can run a query similar to the following. Note that updating the database can lead to problems and you should not do this unless you have exhausted all the above alternatives. Substitute the username you want to promote at the end, and, if necessary, the table name as described above.

```SQL
UPDATE users_customuser SET is_superuser=true, is_staff=true WHERE username='admin';
```

---

*Source: [sentry.io/answers/how-to-reset-django-admin-password/](https://sentry.io/answers/how-to-reset-django-admin-password/)*
