Can I use an existing user as Django admin when enabling admin for the first time?

Yes, but you’ll do it through the Django shell:

python manage.py shell

Then fetch your user from the database:

from django.contrib.auth.models import User
user = User.objects.get(username="myname")
user.is_staff = True
user.is_admin = True
user.save()

Exit the shell, and that user will now be an admin user.

You can also add the line

user.is_superuser = True

before calling user.save() if you want or need this user to be a superuser and have all the available permissions.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)