Django migrations suddenly crash

Hello, I am new to this forum. So far I have always found help for Django problems using internet search, but this time I haven’t found anything close to my problem.
Today I noticed, that when I deploy a new version of our software to our server, the pipeline crashes due to a Django migration command. This does not happen locally, I have spend some time to test and tried to imitate the deployment procedure of the server on my local machine as much as possible, but I cannot reproduce the error locally. The weird thing is, that I even rolled back with Git to a version that was working before and the migration process still breaks.

We are using django-tenants and in the pipeline we start with a fresh database. I first execute makemigrations and everything goes fine. Then, when I run migrate, I get the following error:
File “/usr/local/lib/python3.6/site-packages/django/core/management/commands/”, line 151, in handle
exit_dry = plan and options[‘check_unapplied’]
KeyError: ‘check_unapplied’

This error message comes right after I call the migrate command, there are no succeeding migrations. I’ll post the whole stack trace on the bottom.

I could not find any clue, why this is happening all of the sudden. We install our dependencies via pip and the versions are fixed, so an update of a dependency should not be the cause (Django 3.0.9, django-tenants 3.1). I looked at the code and from what I could see, the parameter should be assigned a default value from the parser, so I don’t even understand how the KeyError could be caused.

Do you have any clue what the cause could be, or maybe a hint/an idea what else I could try or look out for? Thanks

$ python3 migrate

=== Starting migration
Traceback (most recent call last):
File “”, line 16, in
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 401, in
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 395, in execute
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 330, in
self.execute(*args, **cmd_options)
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 371, in execute
output = self.handle(*args, **options)
File “/usr/local/lib/python3.6/site-
packages/django_tenants/management/commands/”, line 49, in handle
File “/usr/local/lib/python3.6/site-packages/django_tenants/migration_executors/”, line 11,
in run_migrations
run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
File “/usr/local/lib/python3.6/site-packages/django_tenants/migration_executors/”, line 36, in
MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options)
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 371, in execute
[ output = self.handle(*args, **options)
File “/usr/local/lib/python3.6/site-packages/django/core/management/”, line 85, in wrapped
res = handle_func(*args, **kwargs)
File “/usr/local/lib/python3.6/site-packages/django/core/management/commands/”, line 151, in handle
exit_dry = plan and options[‘check_unapplied’]
KeyError: ‘check_unapplied’

That almost looks like you’ve got some versions mixed up there. The ‘check_unapplied’ option in the migrate command looks like it’s new in Django 3.1, not in Django 3.0.9.

I’d be tempted to wipe that installation and reinstall the packages from scratch.

Interesting, I think you have a point there since the release date of Django 3.1 coincides exactly with the date of the crash. The weird thing is, that we deploy over Docker images, so technically it should be a clean installation each time. Plus, I have fixed the Django version in a Pipfile.
But it’s a good starting point for investigation, thank you.

The problem is now solved. I looked into the commits and issues of django-tenants and there was indeed an incompatibility with Django 3.1. From deprecation errors I could verify that Django 3.1 was deployed on the server. However that contradicts the specification of the Pipfile and I could not reproduce it locally, where I also install the dependencies via pipenv. I changed the Docker build so the dependencies are now installed via pip and a requirements file and now the correct Django version is installed.