DEV Community 👩‍💻👨‍💻

chris48s
chris48s

Posted on • Originally published at chris48s.github.io

Failing the CI build if django migrations are out of date

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.

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠