Skip to content

Django models and migrations

Cal-ITP Benefits defines a number of models in the core application, used throughout the codebase to configure different parts of the UI and logic.

The Cal-ITP Benefits database is a simple read-only Sqlite database, initialized from the data migration files.


The database is rebuilt from scratch each time the container starts. We maintain a few migration files that set up the schema and load initial data.

These files always represent the current schema and data for the database and match the current structure of the model classes.

Updating models

When models are updated, the migration should be updated as well.

A simple helper script exists to regenerate the migration file based on the current state of models in the local directory:



This script:

  1. Copies the existing migration files to a temporary directory
  2. Runs the django makemigrations command
  3. Copies back any migration files that are missing (data migration file)
  4. Formats the newly regenerated schema migration file with black

This will result in a simple diff of changes on the schema migration file. Commit these changes (including the timestamp!) along with the model changes.