Articles → DJANGO → Create Your First Model In Django

Create Your First Model In Django

Steps Of Creating The Model

  1. Create a new module using the following command
  2. <python_path>\python startapp <module_name>

  3. In the module, add the following code in
  4. from django.db import models
    # Create your models here.
    class MyNewScreen(models.Model):
        name = models.CharField(max_length = 120)
        def __str__(self):

  5. In the root folder, add the module in
  6. Picture showing adding the module in the file
    Click to Enlarge

  7. Inside the module, add following code in
  8. from django.contrib import admin
    # Register your models here.
    from .models import MyNewScreen

  9. In the command prompt, execute the following command
  10. <python path>\python makemigrations
    <python path>\python migrate


Picture showing the administrators screens in Django
Click to Enlarge

Picture showing the database tables created for Django project
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Monday, December 30, 2019
Updated On  -  Thursday, January 16, 2020


Your Email Id  
Query/FeedbackCharacters remaining 250