Django Command Cheat Sheet

This is a list of useful django commands i find being used very often
often you might need to clear the init files and start fresh when making migrations

  find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
  find . -path "*/migrations/*.pyc"  -delete

When working with python in a docker container you may need to run the django commands through docker, docker-compose or whatever other container orchestrating tools you might be using, so for example with docker and docker-compose

  docker-compose run container-microservice-name python manage.py migrate
  docker run container-exact-name python manage.py migrate

when making changes to model structure and importing models from packages to make migrations

  python manage.py makemigrations
  python manage.py migrate

Sometimes you might need to access a python interpreter shell within a django project

  python manage.py shell

When you need to create an admin user

  python manage.py createsuperuser

Add a Comment

Your email address will not be published. Required fields are marked *

account_circle