F O U R T H X
  • Feroz Gandhi Market, Ludhiana, Punjab, India
  • info@fourthX.com
  • +91 740 740 7004

Commonly used Django management commands

Commonly used Django management commands | fourthX
Some of the commonly used Django management commands along with their usage and examples.

startproject: Create a new Django project.
Usage: python manage.py startproject project_name
Example: python manage.py startproject myproject


startapp: Create a new Django app within a project.
Usage: python manage.py startapp app_name
Example: python manage.py startapp myapp


runserver: Run the development server.
Usage: python manage.py runserver [optional_port_number]
Example: python manage.py runserver or python manage.py runserver 8000


makemigrations: Create new database migrations based on changes to models.
Usage: python manage.py makemigrations [app_name]
Example: python manage.py makemigrations or python manage.py makemigrations myapp


migrate: Apply database migrations.
Usage: python manage.py migrate [app_name] [migration_name]
Example: python manage.py migrate or python manage.py migrate myapp


createsuperuser: Create a superuser for accessing the admin interface.
Usage: python manage.py createsuperuser
Example: python manage.py createsuperuser


shell: Open a Python shell with Django environment loaded.
Usage: python manage.py shell
Example: python manage.py shell


collectstatic: Collect static files from all apps into one location.
Usage: python manage.py collectstatic
Example: python manage.py collectstatic


test: Run tests for all apps or specific apps.
Usage: python manage.py test [app_name]
Example: python manage.py test or python manage.py test myapp


dumpdata: Export data from the database in JSON format.
Usage: python manage.py dumpdata [app_name.ModelName]
Example: python manage.py dumpdata myapp.MyModel


loaddata: Load data from a JSON fixture file into the database.
Usage: python manage.py loaddata fixture_file.json
Example: python manage.py loaddata initial_data.json


flush: Delete all data from the database tables.
Usage: python manage.py flush
Example: python manage.py flush

These are just a few examples of Django management commands. You can explore more commands and their options by running python manage.py help or python manage.py help commandName.

Tags: