Model belong to an app. Model names should always be in singular by convention.
Creating a New Model
from django.db import models
class Course(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=255)
description = models.TextField()
We’ve added a new table, so our design has change.
Thus, we need to migrate our database again.
$ python manage.py makemigrations courses
You can find the migration code in the file: courses/migrations/0001_initial.py
$ python manage.py migrate courses
If you don’t specify courses
, Django will migrate everything new in the database.
makemigrations
Simply analyzes your current models for changes and creates a migrations file.
If left at this point, your models would still be out of sync with your database possibly breaking your code that queries the database.
migrate
The command to apply the changes noted during the makemigrations phase.