Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test to check for ungenerated migrations

Has anyone written a unit test to verify if there are ungenerated migrations in their Django app? I think it should probably look something like:

  1. Call python manage.py makemigrations
  2. scrape results into a parsable object
  3. verify "no migrations were found"
  4. if migrations are found list them, fail the test, and delete the generated files

If not, I am going to write one so that we fail our build.

like image 806
Nathan Tregillus Avatar asked Dec 07 '25 16:12

Nathan Tregillus


1 Answers

Since Django 1.10 the makemigrations management command has included a --check option. The command will exit with a non-zero status if migrations are missing.

Usage example:

./manage.py makemigrations --check --dry-run

Documentation:

https://docs.djangoproject.com/en/2.0/ref/django-admin/#cmdoption-makemigrations-check

like image 50
Zathras Avatar answered Dec 09 '25 05:12

Zathras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!