I have 3 environments set up and cannot createsuperuser. The way I migrate and runserver now follows the container so I have an entrypoint.sh:
#!/bin/sh
1
2 echo "${RTE} Runtime Environment - Running entrypoint."
3
4 if [ "$RTE" = "dev" ]; then
5
6 python manage.py makemigrations --merge
7 python manage.py migrate --noinput
8 python manage.py runserver 0:8000
9
10 python manage.py createsuperuser --username "admin" --email "[email protected]" --password "superuser"
11 echo "created superuser"
12
13 elif [ "$RTE" = "test" ]; then
14
15 echo "This is tets."
16 python manage.py makemigrations
17 python manage.py migrate
18 python manage.py runserver
19
20 elif [ "$RTE" = "prod" ]; then
21
22 python manage.py check --deploy
23 python manage.py collectstatic --noinput
24 gunicorn kea_bank.asgi:application -b 0.0.0.0:8080 -k uvicorn.workers.UvicornWorker
25
26 fi
lines 10/11 is what I want to make work, I think I have a syntax issue. Originally I wanted the password and username to be variables stored in an env file:
1 RTE=dev
1 POSTGRES_USER=pguser
2 POSTGRES_PASSWORD=pgpassword
3 POSTGRES_DB=devdb
4 DJANGO_SUPERUSER_PASSWORD=superuser
5 [email protected]
6 DJANGO_SUPERUSER_USERNAME=admin
But now I just want it to work, I need to create a superuser account in order to develop.
Can anyone spot what’s wrong?
I can see my application on localhost:8000, but how do I create the superuser in this scenario?
2
Answers
According to
createsuperuser -h
and this doc,createsuperuser
command does not support--password
flag. to read arguments from environment variables, you should use this command with--noinput
flag and set required fields like username, email and password asDJANGO_SUPERUSER_<uppercase_field_name>
in your env file.python manage.py createsuperuser --noinput
Automate / Create django superuser during docker – compose up.
Create a python file.Like
Keep this file with django project. sometimes docker-compose can not find this because of wrong place of this file. so be careful.
Now in docker-compose.yml under the django project image in command section add. I’m adding details docker-compose file so that you can get help for others section