Create an admin user
A new deployment has an empty database, so nobody can sign in to the Django admin yet. djangocloud superuser sets up the admin user for you: you answer a few questions once, and the user is created when your next release starts.
djangocloud superuserWhat it asks for
Section titled “What it asks for”The CLI asks your project which fields its user model needs, so a custom user model works as well as Django’s default one:
- Default
User: username, email and a password. - A custom model, for example one that signs in with an email address and requires a first name: email, first name and a password. Whatever your model has as
USERNAME_FIELDandREQUIRED_FIELDSis what you are asked for.
To find out, the CLI loads your project on your own machine, in your project’s environment (.venv, uv run or poetry run if you use them). If it can’t load the project, for example because its dependencies aren’t installed there, it says so and assumes Django’s default fields. Check the model it prints before you continue.
What happens
Section titled “What happens”- You type the fields and the password (twice). The password is never shown.
- The CLI saves them as encrypted environment variables, named the way Django expects:
DJANGO_SUPERUSER_USERNAME,DJANGO_SUPERUSER_EMAIL,DJANGO_SUPERUSER_PASSWORD, or for a custom modelDJANGO_SUPERUSER_<FIELD>for each field. - It switches on the
create_superuserbuild setting in.djangocloud/config.json, and offers to deploy right away. - When the release starts, it runs your migrations and then
python manage.py createsuperuser --noinput. The user is created in your database. - Once that deploy is live, the CLI removes
DJANGO_SUPERUSER_PASSWORDfrom your variables and switchescreate_superuseroff again. The password is not kept, and nothing keeps running.
An admin user that already exists is left alone: the command only ever creates a user. It never changes an existing password. A failure never stops your app from starting; the reason is in the release log.
Things to know
Section titled “Things to know”- It works with the managed database and with your own. It runs inside your app, so it uses whatever database your settings point at.
- Deploying from GitHub? The setting is read from the committed
.djangocloud/config.json. Commit it after runningdjangocloud superuser, and remove the password yourself after the deploy withdjangocloud env remove DJANGO_SUPERUSER_PASSWORD. The CLI only cleans up for deploys it uploaded. - A required relation can’t be set this way. If your user model requires a foreign key or many-to-many field, it can’t be passed through an environment variable. The CLI explains this and stops; create the user by hand with
python manage.py createsuperuser. - Can’t log in afterwards? Read the release log of the deploy (
djangocloud logs --source release). The line fromcreatesuperusersays why, for example a validation error. - Forgot the password later? Run
djangocloud superuseragain with a new user, or use Django’schangepasswordcommand. DjangoCloud never has your password after the deploy.
