I have django application 2.1.7 with django-tenant plugin (creating schemas in the database for saas).
My problem is unit testing. I run the command:
python manage.py test --settings=project.settings_test
and I'm getting a error: ImportError: No module named 'notmigrations'
My code in settings_test file
from .settings_base import *
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return 'notmigrations'
MIGRATION_MODULES = DisableMigrations()
You are using an ancient hack intended for really old versions of Django (< 1.9), from before there was support to disable migrations in testing. Since you're now using a relatively recent version of Django (2.1.7), delete that code from your test settings module.
Should you want to disable migrations in tests, use the modern approach, which is putting the value to None
in MIGRATION_MODULES
setting.
When you supply
None
as a value for an app, Django will consider the app as an app without migrations regardless of an existing migrations submodule. This can be used, for example, in a test settings file to skip migrations while testing (tables will still be created for the apps’ models).
# test_settings.py
from settings import *
MIGRATION_MODULES = {
'auth': None,
'contenttypes': None,
'sessions': None,
...
'myapp1': None,
'myapp2': None,
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With