Skip to content

Understanding Django Database Migrations

Posted on:November 22, 2023 at 12:00 AM

Why does Django need an ORM?

Django’s ORM provides the contract between the database schema and application code. It ensures the application can access the data layout it expects.

References:

What is the purpose of Django migrations?

Django migrations handle changes to the database schema as the data needs change over the application lifetime. They migrate the database to match the new data model.

References:

How do Django migrations work?

The workflow is:

  1. Change the data models
  2. Generate migration files
  3. Apply migrations to update the database

References:

Which table stores Django migration information?

The django_migrations table records all the applied database migrations.

References:

Why does Django run migrations for each test?

Migrations can alter data, install extensions, run SQL, etc. So Django must run all migrations to ensure the test database matches expectations.

References: