Skip to content

Django Cheat Sheet



The article covers several important database operation commands such as createcachetable, dbshell, dumpdata, flush, inspectdb, loaddata, makemigrations, migrate, showmigrations, sqlflush, sqlmigrate, sqlsequencereset, squashmigrations, and testserver. These commands will help you to manage your database more efficiently and will save you a lot of time.

Moreover, the article also covers several environment configuration commands such as startproject, startapp, compilemessages, and makemessages. These commands will help you to set up your Django environment quickly and easily.

Lastly, the article covers development debugging commands such as check, diffsettings, runserver, shell, sendtestemail, and test. These commands will help you to debug your application and test it thoroughly.

Database operation commands


Create a data table for caching, which is used to support the caching middleware declared in the configuration file.

django-admin createcachetable

--database DATABASE
## Used to specify the database where the cache table is generated. By default, this parameter specifies the database set in the default setting of the configuration file.


Use the database engine set in the configuration file through the command line.

django-admin dbshell



Export the database table data of the specified application.

django-admin dumpdata [app_label[.ModelName]



Remove the data from the business table in the database, while the tables related to the records generated by migrate are not deleted.

django-admin flush



Check all tables in the database and generate output model classes for each table.

django-admin inspectdb [table [table ...]]



Query fixed information content and import it into the database.

django-admin loaddata fixture [fixture ...]



Generate a database migration script file based on the detection result of the model in the project.

django-admin makemigrations [app_label [app_label ...]]



Synchronize the database based on the model and migration file information.

django-admin migrate [app_label] [migration_name]



View the existing database synchronization scripts in the project.

django-admin showmigrations [app_label [app_label ...]]



View the script that clears the database.

django-admin sqlflush



View the SQL statement of the specified name database synchronization.

django-admin sqlmigrate app_label migration_name



Generate a script corresponding to the sequence used in the table related to the specified application.

django-admin sqlsequencereset app_label [app_label ...]



Generate merged migration files and merge multiple migration script files under the application into a few possible ones. The migration files before merging and after merging can coexist.

django-admin squashmigrations app_label [start_migration_name]migration_name

--noinput, --no-input

Environment configuration command


Create a Django project directory framework with the specified project name in the current directory or given address.

django-admin startproject name [directory]


Create an app.

django-admin startapp name [directory]



Compile .po language files (generated by the makemessages method) for international language support.

django-admin compilemessages



Check and extract the information to be translated in all files in the project file.

django-admin makemessages


Development debugging commands


Check if there are potential problems in the overall Django project and whether the required associated files of the project are complete. By default, check all applications under the project.

django-admin check [app_label [app_label ...]]



Display the differences between the current project’s configuration file and the default Django configuration file.

django-admin diffsettings



Start locally.

django-admin runserver [addr:port]



Enter the Django shell.

django-admin shell



Send a test email.

django-admin sendtestemail [email [email ...]]



Test the Django project.

django-admin test [test_label [test_label ...]]



Use the given data to run the Django development server.

django-admin testserver [fixture [fixture ...]]

Small world. Big idea!
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • No personal information is collected
  • Made with Material for MkDocs and generative AI tools
  • Copyright issue feedback, replace # with @
  • Get latest SRE news and discuss on Discord Channel