Here is a comprehensive list of all the commonly used manage.py commands in Django, along with descriptions of what each command does:
-
python manage.py runserver- Starts the development server on the default port
8000. - You can specify the port and IP, for example:
python manage.py runserver 8080.
- Starts the development server on the default port
-
python manage.py migrate- Applies migrations to the database, creating or updating tables based on the models defined in the project.
-
python manage.py makemigrations- Creates new migrations based on the changes detected in your models.
-
python manage.py createsuperuser- Creates a new superuser account with admin privileges.
-
python manage.py startapp <appname>- Creates a new Django app with the provided name within the project.
-
python manage.py startproject <projectname>- Starts a new Django project with the provided project name.
-
python manage.py shell- Opens the interactive Python shell, with your Django environment pre-loaded.
-
python manage.py sqlmigrate <app_label> <migration_number>- Displays the raw SQL for a specific migration for a given app and migration number.
-
python manage.py showmigrations- Shows all migrations and their applied/unapplied status.
-
python manage.py dbshell- Opens the database shell for running SQL queries directly on the database.
-
python manage.py collectstatic- Gathers all static files from your apps into a single directory (usually for deployment).
-
python manage.py check- Checks the project for potential problems or errors without making any database changes.
-
python manage.py test- Runs the test suite for the project to ensure code quality and correctness.
-
python manage.py flush- Deletes all data in the database and returns it to the initial migration state.
-
python manage.py changepassword <username>- Changes the password for the specified user.
-
python manage.py diffsettings- Shows the difference between the current settings file and Django’s default settings.
-
python manage.py loaddata <fixture_file>- Loads data from a fixture file into the database.
-
python manage.py dumpdata <app_label.ModelName>- Outputs the contents of a model as a JSON fixture file.
-
python manage.py clearsessions- Clears expired sessions from the database.
-
python manage.py sqlflush- Returns the SQL commands needed to flush the database (used with
flush).
- Returns the SQL commands needed to flush the database (used with
-
python manage.py inspectdb- Generates models from an existing database.
-
python manage.py compilemessages- Compiles
.pofiles to.mofiles for translation.
- Compiles
-
python manage.py makemessages -l <language_code>- Extracts all translatable strings into a
.pofile for a given language.
- Extracts all translatable strings into a
-
python manage.py createsuperuser- Allows you to create an admin user interactively via the terminal.
-
python manage.py collectstatic- Collects static files into the location defined in
STATIC_ROOTfor production use.
- Collects static files into the location defined in
-
python manage.py migrate --fake <app_label> <migration_name>- Marks the migration as applied without actually running it, useful in certain advanced migration cases.
-
python manage.py showmigrations <app_label>- Lists the migration status for a specific app.
-
python manage.py sqlsequencereset <app_label>- Resets the database sequence for an app’s models (useful when working with PostgreSQL or other databases that use sequences).
-
python manage.py graph_models- Generates a visual graph of your models using Graphviz.
-
python manage.py runscript <script_name>- Runs a custom script placed in a special directory.
-
python manage.py show_urls- Displays all of the URLs configured in your project.
These are the essential manage.py commands you’ll use when working with a Django project, covering development, testing, migration management, and administration tasks.