Django migrations help track and apply changes made to your models into the database schema using the makemigrations and migrate commands.
makemigrations creates migration files, while migrate applies them to the database.
# Create migration files for all apps
python manage.py makemigrations
# Apply all pending migrations
python manage.py migrate
# Django model with a newly added field
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.IntegerField()
Simulate the workflow! Add a field to the model, generate a migration file, and apply it to the database.
After running migrations, Django updates the database schema to match the models. New tables or columns become available without data loss.
Think of migrations as a timeline: each migration is a step that moves your database forward safely, one change at a time.