The Wayback Machine - https://web.archive.org/web/20240719005653/https://www.geeksforgeeks.org/django-app-model-python-manage-py-makemigrations-command/
Open In App

Django App Model – Python manage.py makemigrations command

Last Updated : 26 Sep, 2019
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

According to documentation, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into.

makemigrations are run through the following command

Python manage.py makemigrations

If the above commands says no changes detected, You can also do it for individual apps.
For example if you have 10 apps named a, b, c, d, e, f, g, h, i, j. You can run makemigrations individually for these apps.

Python manage.py makemigrations a 
Python manage.py makemigrations b 
Python manage.py makemigrations c 

and so on.

Django app model makemigrations

makemigrations basically generates the SQL commands for preinstalled apps (which can be viewed in installed apps in settings.py) and your newly created apps’ model which you add in installed apps. It does not execute those commands in your database file. So tables are not created after makemigrations.

After applying makemigrations you can see those SQL commands with sqlmigrate which shows all the SQL commands which have been generated by makemigrations.

For example, if we make a model class-




from django.db import models
  
class Person(models.Model):
    first_name = models.CharField(max_length = 30)
    last_name = models.CharField(max_length = 30)


The corresponding sql command after using makemigrations will be

CREATE TABLE myapp_person (
"id" serial NOT NULL PRIMARY KEY,
"first_name" varchar(30) NOT NULL,
"last_name" varchar(30) NOT NULL
);

and using above command, table will be created in the database when we use migrate.



Similar Reads

Django Basic App Model - Makemigrations and Migrate
In this article, we will create a basic model of an app and also learn about what are migrations in Django and migrate in Django also develop some basic understanding related to them in Python. Makemigrations and Migrations in DjangoMakemigrations and migrate are commands that are used to interact with Django models. Let's understand in detail. Mak
5 min read
Django manage.py migrate command | Python
According to documentation, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations when to run them, and the common problems you might run into. migrate is run through the f
2 min read
Understanding Django: Model() vs Model.objects.create()
In Django, when working with models, understanding the differences between Model() and Model.objects.create() is crucial for effective database operations. Both methods serve distinct purposes and are used in different contexts within Django's ORM (Object-Relational Mapping). The Basics: Django ModelsIn Django, a model is a Python class that subcla
3 min read
Adding Tags Using Django-Taggit in Django Project
Django-Taggit is a Django application which is used to add tags to blogs, articles etc. It makes very easy for us to make adding the tags functionality to our django project.Setting up Django Project Installing django-taggit pip install django-taggitADD it to Main Project's settings.py file C/C++ Code INSTALLED_APPS = [ 'django.contrib.admin', 'dja
2 min read
How to customize Django forms using Django Widget Tweaks ?
Django forms are a great feature to create usable forms with just few lines of code. But Django doesn't easily let us edit the form for good designs. Here, we will see one of the ways to customize Django forms, So they will look according to our wish on our HTML page. Basically we will check the methods to include our own custom css, classes, or id
3 min read
Integrating Django with Reactjs using Django REST Framework
In this article, we will learn the process of communicating between the Django Backend and React js frontend using the Django REST Framework. For the sake of a better understanding of the concept, we will be building a Simple Task Manager and go through the primary concepts for this type of integration between React js and Django. Reactjs in a nuts
15+ min read
Styling Django Forms with django-crispy-forms
Django by default doesn't provide any Django form styling method due to which it takes a lot of effort and precious time to beautifully style a form. django-crispy-forms solves this problem for us. It will let you control the rendering behavior of your Django forms in a very elegant and DRY way. Modules required:django : django installdjango-crispy
1 min read
Discuss Different Types of Shell Command in Django
Django, a high-level Python web framework, streamlines the development of robust and scalable web applications. One of the essential tools Django provides is its shell commands. These commands, accessible through the Django management command interface, are invaluable for interacting with your Django project, managing database operations, and debug
4 min read
Different types of Filter Command for Database in Django
Django follows the Model-View-Controller (MVC) architectural pattern, although it’s referred to as Model-View-Template (MVT) in Django terminology: Model: Defines the data structure.View: Manages the logic and interaction.Template: Manages presentation and rendering to the user.How Django's ORM Processes QueriesDjango's ORM allows developers to int
4 min read
Python | Django News App
Django is a high-level framework which is written in Python which allows us to create server-side web applications. In this article, we will see how to create a News application using Django. We will be using News Api and fetch all the headline news from the api. Read more about the api here news api.Do the Following steps in command prompt or term
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg