Challenge 3: Explore manage.py — Possible Solution ==================================================================== $ python manage.py help # (abbreviated — the real output lists many more, grouped by app) # # [django] # check # dbshell # diffsettings # makemigrations # migrate # runserver # shell # showmigrations # startapp # startproject # test THREE SUBCOMMANDS, EXPLAINED ----------------------------- 1. python manage.py shell Opens an interactive Python REPL with Django already configured and your project's settings loaded — meaning you can immediately import and query your own models (e.g. `from catalog.models import Book; Book.objects.all()`) without manually setting up Django first. Reach for this when you want to quickly inspect or manipulate real data without writing a throwaway script or view. 2. python manage.py dbshell Drops you into your database's own native command-line client (psql for PostgreSQL, the sqlite3 CLI for SQLite, etc.), already connected to the project's configured database — no need to look up or type the connection string yourself. Reach for this when you want to run a raw SQL query directly, outside of anything Django's ORM would generate. 3. python manage.py showmigrations Lists every app's migrations and marks which ones have actually been applied to the current database ([X]) versus which are still pending ([ ]). Reach for this when `migrate` behaves unexpectedly, or before deploying, to confirm the database is in the state your code expects. WHY THIS WORKS -------------- - manage.py help surfaces Django's own built-in commands grouped by the app that defines them (most of the ones above come from "django" core itself, but a third-party app or your own app can register additional subcommands the same way) — this is the fastest way to discover what's available without searching documentation first. - Each command exists because Django assumes certain tasks are common enough across nearly every project (inspecting data, running raw SQL, checking migration state) that they deserve a first-class command rather than requiring a hand-written script — another small instance of the "batteries included" theme from this chapter. - Building the habit of running `manage.py help` when unsure what's available (rather than only learning commands one at a time as tutorials mention them) pays off as Django projects grow more complex.