Skip to main content

Standard Django Commands

These are built-in commands that come with every Django project and are essential for general maintenance and administration.

Database Management

makemigrations

docker exec -it triviaflow_app python manage.py makemigrations

Purpose:
Scans your models (code) and creates new "migration files" for any changes you made. This prepares the changes but doesn't apply them yet.

When to use:

  • Whenever you have made changes to models.py.
  • Before running migrate.

migrate

docker exec -it triviaflow_app python manage.py migrate

Purpose:
Applies the migration files to your actual database. This creates tables, builds relationships, and modifies columns.

When to use:

  • Always after pulling new code or updating the docker container.
  • After creating new migrations with makemigrations.

Static Files

collectstatic

docker exec -it triviaflow_app python manage.py collectstatic

Purpose:
Collects all static files (CSS, JS, images) from each of your app folders and copies them into a single STATIC_ROOT directory.

When to use:

  • When deploying to production.
  • If specific static assets are not loading correctly after an update.
  • Important for ensuring Nginx/Apache serves your files efficiently.

Admin & Debugging

createsuperuser

docker exec -it triviaflow_app python manage.py createsuperuser

Purpose:
Creates a new administrative user with full access to the Django Admin panel (usually at /admin/).

When to use:

  • When you first install the application to create your initial login.
  • If you are locked out and need a new admin account.

shell

docker exec -it triviaflow_app python manage.py shell

Purpose:
Opens an interactive Python shell with all your Django settings and models loaded.

When to use:

  • For advanced debugging.
  • To manually query the database using Python scripting.
  • To test snippets of code within the application context.

test

docker exec -it triviaflow_app python manage.py test

Purpose:
Runs the test suite to ensure your code is working correctly.

When to use:

  • After making code changes to verify you haven't broken existing functionality.
  • As part of a CI/CD pipeline.