I used Tk421 one liner, but received an error message like: 1) I think that I am using a later version of Django (1.10) Manager isn't available; 'auth.User' has been swapped for 'users.User' Manager isn't available; 'auth.User' has been swapped for 'users.User' 2), the order of the parameters for create_superuser was incorrect.
So I replaced it with:
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(email='admin@example.com', is_superuser=True).delete(); User.objects.create_superuser('admin', 'admin@example.com', 'nimda')" | python manage.py shell
and what I like so much is that it works with the deployment of heroku too:
heroku run echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(email='admin@example.com', is_superuser=True).delete(); User.objects.create_superuser('admin', 'admin@example.com', 'nimda')" | python manage.py shell
This will work repeatedly. I use it at the beginning of the project, so donβt worry about scary cascading deletions that may occur later.
I changed my mind after some problems running this inside local () from a fabric. what seemed to be happening was that the pipe symbol means that it is interpreted locally and not on the hero. To sort this, I wrapped the command in quotation marks. Then I had to use triple double quotes for python strings inside the single quotes of the entire python command.
heroku run "echo 'from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.filter(email="""admin@example.com""", is_superuser=True).delete(); User.objects.create_superuser("""admin""", """admin@example.com""", """nimda""")' | python manage.py shell"
hum3 Jun 14 '17 at 15:10 2017-06-14 15:10
source share