Django Manage Commands Cheat Sheet

Django Manage Commands Cheat Sheet

  • Valeria Aynbinder
  • Coding
  • 12 Aug, 2024

Installations

In order to get started with Django, all you need to do is install Django package using pip:

pip install django

After the installation is complete, you can move forward and create your Django application.

Django Application Creation

Creating a new Django web application consists of two stages:

First, you need to create a new Django project:

django-admin startproject my_project

Note: my_project is a custom name for your project

Project tree after running startproject

Second, you need to create a new Django application that will sit inside the newly created project. In order to do this, you need to change directory to my_project (the one where manage.py file resides):

cd my_project
python manage.py startapp my_app

*Note:*my_app is a custom name for your application

After running this command your project tree will look similar to this:

Project folder after running startapp command

DB management

Create migration

(this should be run after you make changes to your models.py):

python manage.py makemigrations

This command will result in creating a new migration file in your migrations folder:

Migration files inside migrations folder

SQL Migrate

(Review SQL queries that will actually run on your DB server during migrate)

python manage.py sqlmigrate my_app 0001

Note: my_app and 0001 are your app name and migration name respectively

Migrate

(this should be run when you want to apply changes in your migration files on your DB)

python manage.py migrate

Other useful commands

Create superuser

Use this command in order to create superuser that will allow you to login into Django Admin App

python manage.py createsuperuser

Django Shell

Use this command to start Django Shell with your application and models loaded (very useful when you want to play with Django models a bit)

python manage.py shell

Django has loaded your Django application for you, so now you can play with your Django models in Python shell!

Playing with Django Models in Django Shell

Tags :
Share :

Related Post

Python Decorators - Deep Dive in 2 Parts (1/2)

Python Decorators - Deep Dive in 2 Parts (1/2)

  • Valeria Aynbinder
  • Coding
  • 12 Jul, 2024

This is a 2-Part Series:Part 1 (current): Intro + Build Your First Decorator Part 2: [Decorators for functions that receive parameters and return values, decorators that receive argu

Read More
Python Decorators - Deep Dive in 2 Parts (2/2)

Python Decorators - Deep Dive in 2 Parts (2/2)

  • Valeria Aynbinder
  • Coding
  • 17 Jul, 2024

This is a 2-Part Series:Part 1: Intro + Build Your First Decorator Part 2 (current): Decorators for functions that receive parameters an

Read More
Python Sets — A Powerful Collection Every Developer Should Use

Python Sets — A Powerful Collection Every Developer Should Use

  • Valeria Aynbinder
  • Coding
  • 10 Sep, 2024

Introduction There are three basic Python collections: list, dictionary, and set. While list and dictionary are widely used in almost every piece of Python code, the set sometimes

Read More
Google Colab - a must-have tool for Developer and Data Scientist

Google Colab - a must-have tool for Developer and Data Scientist

13 amazing features and usage tips.What is Google Colab?Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows an

Read More
Python Regular Expressions - Cheat Sheet

Python Regular Expressions - Cheat Sheet

  • Valeria Aynbinder
  • Coding
  • 16 Oct, 2024

Many code examples + useful tips. Bonus added to the end of the post.Regular expressions is an extremely useful tool, and like any developer, I use it a lot when working with texts. Since I al

Read More