What are Django migrations?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Django development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
Django migrations are Django's version control system for database schema changes. When you modify models (add fields, change types, create new models), migrations record those changes and apply them to the database. Workflow: (1) Modify models.py (add a field, change a model); (2) python manage.py makemigrations — creates a migration file in app/migrations/ describing the changes; (3) python manage.py migrate — applies pending migrations to the database. Migration commands: python manage.py makemigrations — detect and create new migrations; python manage.py migrate — apply all pending; python manage.py migrate myapp 0003 — migrate to specific version; python manage.py showmigrations — list all migrations and applied status; python manage.py sqlmigrate myapp 0003 — show the SQL for a migration; python manage.py migrate myapp zero — revert all migrations for an app. Migration files: plain Python files with operations list: migrations.AddField(), migrations.RemoveField(), migrations.CreateModel(), migrations.RunSQL(). Data migrations: migrations.RunPython() for custom data manipulation during migration. Important: commit migration files to version control — they're part of your schema history. Squash migrations for cleaner history: python manage.py squashmigrations myapp 0001 0010.
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Django project.