Today’s Offer Enroll today and get access to premium content.
App Store Google Play
Intermediate

How do you create and apply migrations in Django?

Migrations in Django are used to propagate changes you make to your models (adding a field, deleting a model, etc.) into the database schema. To create and apply migrations, follow these steps:

  1. Make changes to your models in models.py.
  2. Run
    python manage.py makemigrations
    to create a migration file.
  3. Run
    python manage.py migrate
    to apply the migration to the database.

This process ensures your database schema is synchronized with your models. For instance, if you add a new field published_date to a model, running these commands updates the database accordingly.