Changing a Model and Re-migrating
Add a field and roll the change into the DB.
Models Evolve
Real apps change. When a feature needs a new column, you edit the model and let migrations carry the change to the database.
Step 1: Edit the Model
Start by adding the field in your model class. Here you give a Post a published flag with a sensible default.
class Post(models.Model):
title = models.CharField(max_length=200)
published = models.BooleanField(default=False)All lessons in this course
- makemigrations vs migrate
- Reading a Migration File
- Changing a Model and Re-migrating
- sqlmigrate and Inspecting SQL