Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django delete superuser

Tags:

python

django

This may be a duplicate, but I couldn't find the question anywhere, so I'll go ahead and ask:

Is there a simple way to delete a superuser from the terminal, perhaps analogous to Django's createsuperuser command?

like image 541
Quentin Donnellan Avatar asked Nov 03 '14 11:11

Quentin Donnellan


People also ask

Can I delete superuser in Django?

There is no way to delete it from the Terminal (unfortunately), but you can delete it directly. Just log into the admin page, click on the user you want to delete, scroll down to the bottom and press delete.

What is Django superuser?

superuser. - The most powerful user with permissions to create, read, update and delete data in the Django admin, which includes model records and other users.

How many superuser can be created in Django?

Note that this won't prevent from setting a user as being a superuser from django admin interface. If you want to completely make it impossible to create two superusers, you can add the constraint on the database level directly.


2 Answers

There's no built in command but you can easily do this from the shell:

> python manage.py shell $ from django.contrib.auth.models import User $ User.objects.get(username="joebloggs", is_superuser=True).delete() 
like image 191
Timmy O'Mahony Avatar answered Oct 04 '22 11:10

Timmy O'Mahony


No need to delete superuser...just create another superuser... You can create another superuser with same name as the previous one. I have forgotten the password of the superuser so I create another superuser with the same name as previously.

like image 32
Shubham Mahitkar Avatar answered Oct 04 '22 13:10

Shubham Mahitkar