Failing the CI build if django migrations are out of date
chris48s

chris48s @chris48s

Joined:
May 3, 2021

Failing the CI build if django migrations are out of date

Publish Date: May 12 '21
4 0

A common mistake in django is to make a model change but forget to run makemigrations to generate a migration for the model change. Sometimes it is not entirely obvious when this need to happen. For example, let's say I'm using the django-extensions library and I define a model like:

# models.py

from django.db import models
from django_extensions.db.models import TimeStampedModel

class MyModel(TimeStampedModel, models.Model):
    pass
Enter fullscreen mode Exit fullscreen mode

In this situation, upgrading django-extensions to a new version might require me to regenerate the migrations in my app, even though I haven't made any changes to models.py and overlooking this could generate unexpected results.

Fortunately there is a simple thing I can do to detect and warn if this happens: If I run

python manage.py makemigrations --check
Enter fullscreen mode Exit fullscreen mode

in my CI build, this will cause the build to fail if my migrations are out of sync with the models, warning me about the problem.

Comments 0 total

    Add comment