0PricingLogin
Django Academy · Lesson

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

  1. makemigrations vs migrate
  2. Reading a Migration File
  3. Changing a Model and Re-migrating
  4. sqlmigrate and Inspecting SQL
← Back to Django Academy