django-admin utility provides commands for common Django administrative tasks. When using manage.py, the commands are the same.
Project & App Creation
startproject
Creates a Django project directory structure for the given project name.Name of the project to create.
Optional destination directory. Will be created if it doesn’t exist.
Path or URL to load the template from.
File extension(s) to render (default: “py”). Separate multiple extensions with commas, or use
-e multiple times.File name(s) to render. Separate multiple names with commas, or use
-n multiple times.Directory name(s) to exclude, in addition to .git and pycache.
The project name should be a valid Python identifier (no hyphens, must not conflict with Python or Django package names).
startapp
Creates a Django app directory structure for the given app name.Name of the application to create.
Optional destination directory. Will be created if it doesn’t exist.
Path or URL to load the template from.
File extension(s) to render (default: “py”).
File name(s) to render.
Database Migrations
makemigrations
Creates new migration files based on model changes.Specify app label(s) to create migrations for. If omitted, creates migrations for all apps.
Show what migrations would be made without actually writing them.
Enable fixing of migration conflicts.
Create an empty migration.
Tells Django NOT to prompt for input.
Use this name for migration file(s).
Exit with non-zero status if model changes are missing migrations. Implies —dry-run.
Divert log output to stderr, writing only migration file paths to stdout.
Merge model changes into the latest migration and optimize operations.
migrate
Applies and unapplies migrations to synchronize the database schema with models.App label to synchronize the state for.
Migrate to this specific migration. Use “zero” to unapply all migrations.
Nominates a database to synchronize. Defaults to “default”.
Mark migrations as run without actually running them.
Detect if tables already exist and fake-apply initial migrations if so.
Shows a list of migration actions that will be performed.
Creates tables for apps without migrations.
Tells Django NOT to prompt for input.
Exit with non-zero status if unapplied migrations exist. Does not apply migrations.
Delete nonexistent migrations from the django_migrations table.
Always backup your database before running migrations in production.
Development Server
runserver
Starts a lightweight development web server.Optional port number or ipaddr:port. Default is 127.0.0.1:8000.
Tells Django to use an IPv6 address.
Tells Django NOT to use threading.
Tells Django NOT to use the auto-reloader.
DO NOT use this server in production. It’s designed for development only and hasn’t been audited for security or performance.
Interactive Shell
shell
Runs a Python interactive interpreter with Django environment loaded.Specify an interactive interpreter interface: “ipython”, “bpython”, or “python”.
When using plain Python, ignore PYTHONSTARTUP environment variable and ~/.pythonrc.py script.
Disable automatic imports of models.
Instead of opening an interactive shell, run a command as Django and exit.
django.conf.settingsdjango.db.connectiondjango.db.modelsdjango.db.models.functionsdjango.db.reset_queriesdjango.utils.timezone- All models from
INSTALLED_APPS
System Checks
check
Checks the entire Django project for potential problems.Check specific app(s) only.
Run only checks labeled with given tag. Can be used multiple times.
List available tags.
Check deployment settings.
Message level that will cause the command to exit with non-zero status. Choices: CRITICAL, ERROR, WARNING, INFO, DEBUG. Default is ERROR.
Run database related checks against specific aliases. Can be used multiple times.
Other Useful Commands
showmigrations
Shows all available migrations and which have been applied.sqlmigrate
Displays the SQL statements for a migration.dbshell
Runs the command-line client for the database engine specified in your settings.flush
Removes all data from the database and re-executes any post-synchronization handlers.This is a destructive operation. Use with caution.
dumpdata
Outputs all data from the database (or a specific app/model) as JSON, XML, or YAML.loaddata
Loads data from a fixture file into the database.createsuperuser
Creates a superuser account for the Django admin.changepassword
Changes a user’s password.collectstatic
Collects static files from all apps intoSTATIC_ROOT.