Changing a Model and Re-migrating
Add a field and roll the change into the DB.
Changing a Model and Re-migrating is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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)Step 2: makemigrations
Run makemigrations. Django diffs the new model against the last one and writes a fresh migration for the added field.
python manage.py makemigrationsStep 3: migrate
Run migrate to apply the new file. The column now exists in the real table, ready to use.
python manage.py migrateDefaults Fill Old Rows
Adding a non-nullable field to a populated table needs a value for existing rows. A default fills them in cleanly.
No Default? Django Asks
Without a default, makemigrations stops and prompts you to provide a one-off value for existing rows before continuing.
Each Change Is a New File
Django never edits old migrations. Every model change becomes a new numbered file stacked on top of the last.
Renaming a Field
Rename a field and Django may ask if you renamed rather than dropped-and-added. Answer yes to keep the column data.
Removing a Field
Delete a field from the model, then makemigrations writes a RemoveField step. Apply it and the column is gone for good.
Reversing a Migration
To undo, migrate back to an earlier number. Django runs the migrations in reverse to restore the previous schema.
python manage.py migrate blog 0001Commit the Files
Always commit the new migration with your model edits. Teammates run migrate and get the same schema, no surprises.
Quick Check
You add a required field to a table that already has rows. What does Django need?
Recap
The loop is simple: edit the model, makemigrations, migrate, commit. Each change becomes a new file, so your history stays honest. ✅
Frequently asked questions
Is the “Changing a Model and Re-migrating” lesson free?
Yes — the full text of “Changing a Model and Re-migrating” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “Changing a Model and Re-migrating”?
Add a field and roll the change into the DB. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Changing a Model and Re-migrating” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- makemigrations vs migrate
- Reading a Migration File
- Changing a Model and Re-migrating
- sqlmigrate and Inspecting SQL