Skip to main content
The 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.
django-admin startproject myproject
django-admin startproject myproject /path/to/destination
name
string
required
Name of the project to create.
directory
string
Optional destination directory. Will be created if it doesn’t exist.
--template
string
Path or URL to load the template from.
--extension
string
File extension(s) to render (default: “py”). Separate multiple extensions with commas, or use -e multiple times.
--name
string
File name(s) to render. Separate multiple names with commas, or use -n multiple times.
--exclude
string
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.
python manage.py startapp myapp
python manage.py startapp myapp /path/to/destination
name
string
required
Name of the application to create.
directory
string
Optional destination directory. Will be created if it doesn’t exist.
--template
string
Path or URL to load the template from.
--extension
string
File extension(s) to render (default: “py”).
--name
string
File name(s) to render.

Database Migrations

makemigrations

Creates new migration files based on model changes.
python manage.py makemigrations
python manage.py makemigrations myapp
python manage.py makemigrations --dry-run
python manage.py makemigrations --name custom_migration_name
app_label
string
Specify app label(s) to create migrations for. If omitted, creates migrations for all apps.
--dry-run
bool
Show what migrations would be made without actually writing them.
--merge
bool
Enable fixing of migration conflicts.
--empty
bool
Create an empty migration.
--noinput
bool
Tells Django NOT to prompt for input.
--name
string
Use this name for migration file(s).
--check
bool
Exit with non-zero status if model changes are missing migrations. Implies —dry-run.
--scriptable
bool
Divert log output to stderr, writing only migration file paths to stdout.
--update
bool
Merge model changes into the latest migration and optimize operations.

migrate

Applies and unapplies migrations to synchronize the database schema with models.
python manage.py migrate
python manage.py migrate myapp
python manage.py migrate myapp 0001_initial
python manage.py migrate myapp zero
app_label
string
App label to synchronize the state for.
migration_name
string
Migrate to this specific migration. Use “zero” to unapply all migrations.
--database
string
Nominates a database to synchronize. Defaults to “default”.
--fake
bool
Mark migrations as run without actually running them.
--fake-initial
bool
Detect if tables already exist and fake-apply initial migrations if so.
--plan
bool
Shows a list of migration actions that will be performed.
--run-syncdb
bool
Creates tables for apps without migrations.
--noinput
bool
Tells Django NOT to prompt for input.
--check
bool
Exit with non-zero status if unapplied migrations exist. Does not apply migrations.
--prune
bool
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.
python manage.py runserver
python manage.py runserver 8080
python manage.py runserver 0.0.0.0:8000
python manage.py runserver --noreload
addrport
string
Optional port number or ipaddr:port. Default is 127.0.0.1:8000.
--ipv6
bool
Tells Django to use an IPv6 address.
--nothreading
bool
Tells Django NOT to use threading.
--noreload
bool
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.
python manage.py shell
python manage.py shell --interface ipython
python manage.py shell -c "from myapp.models import MyModel; print(MyModel.objects.count())"
--interface
string
Specify an interactive interpreter interface: “ipython”, “bpython”, or “python”.
--no-startup
bool
When using plain Python, ignore PYTHONSTARTUP environment variable and ~/.pythonrc.py script.
--no-imports
bool
Disable automatic imports of models.
--command
string
Instead of opening an interactive shell, run a command as Django and exit.
The shell automatically imports:
  • django.conf.settings
  • django.db.connection
  • django.db.models
  • django.db.models.functions
  • django.db.reset_queries
  • django.utils.timezone
  • All models from INSTALLED_APPS

System Checks

check

Checks the entire Django project for potential problems.
python manage.py check
python manage.py check myapp
python manage.py check --tag models
python manage.py check --deploy
app_label
string
Check specific app(s) only.
--tag
string
Run only checks labeled with given tag. Can be used multiple times.
--list-tags
bool
List available tags.
--deploy
bool
Check deployment settings.
--fail-level
string
Message level that will cause the command to exit with non-zero status. Choices: CRITICAL, ERROR, WARNING, INFO, DEBUG. Default is ERROR.
--database
string
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.
python manage.py showmigrations
python manage.py showmigrations myapp
python manage.py showmigrations --plan

sqlmigrate

Displays the SQL statements for a migration.
python manage.py sqlmigrate myapp 0001

dbshell

Runs the command-line client for the database engine specified in your settings.
python manage.py dbshell

flush

Removes all data from the database and re-executes any post-synchronization handlers.
python manage.py flush
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.
python manage.py dumpdata
python manage.py dumpdata myapp
python manage.py dumpdata myapp.MyModel

loaddata

Loads data from a fixture file into the database.
python manage.py loaddata fixture.json

createsuperuser

Creates a superuser account for the Django admin.
python manage.py createsuperuser

changepassword

Changes a user’s password.
python manage.py changepassword username

collectstatic

Collects static files from all apps into STATIC_ROOT.
python manage.py collectstatic
python manage.py collectstatic --noinput

test

Runs tests for all installed apps or specific apps.
python manage.py test
python manage.py test myapp
python manage.py test myapp.tests.MyTestCase

compilemessages

Compiles .po files to .mo files for use with gettext.
python manage.py compilemessages
python manage.py compilemessages --locale=pt_BR

makemessages

Runs over the entire source tree and pulls out all strings marked for translation. It creates (or updates) message files in the locale directory.
python manage.py makemessages -l pt_BR
python manage.py makemessages --all

createcachetable

Creates the database tables needed for the database cache backend.
python manage.py createcachetable

diffsettings

Displays differences between the current settings and Django’s default settings.
python manage.py diffsettings
python manage.py diffsettings --all

inspectdb

Introspects the database tables and outputs a Django model module to standard output.
python manage.py inspectdb
python manage.py inspectdb table_name

sqlflush

Returns SQL statements that would be executed for the flush command.
python manage.py sqlflush

sqlsequencereset

Prints the SQL statements for resetting sequences for the given app names.
python manage.py sqlsequencereset myapp

squashmigrations

Squashes a range of migrations for an app into a single migration.
python manage.py squashmigrations myapp 0001 0004

testserver

Runs the development server with data from given fixture files.
python manage.py testserver fixture1.json fixture2.json

sendtestemail

Sends a test email to confirm email settings are configured correctly.
python manage.py sendtestemail [email protected]

optimizemigration

Optimizes a migration by removing redundant operations.
python manage.py optimizemigration myapp 0002

Build docs developers (and LLMs) love