-
-
Save NotSqrt/5f3c76cd15e40ef62d09 to your computer and use it in GitHub Desktop.
class DisableMigrations(object): | |
def __contains__(self, item): | |
return True | |
def __getitem__(self, item): | |
return "notmigrations" | |
MIGRATION_MODULES = DisableMigrations() |
Based on the same source as this app, I use something like this in my settings:
RUN_MODE = sys.argv[1] if len(sys.argv) > 1 else None
if RUN_MODE == 'test':
class DisableMigrations(dict):
except_apps = {'app_to_run_migrations_for'}
def __contains__(self, item):
return item not in self.except_apps
def __getitem__(self, item):
return super(DisableMigrations, self).__getitem__(item) if item in self.except_apps else None
MIGRATION_MODULES = DisableMigrations()
Not sure if someone else has the issue, but when I tried this snipped on my project that contains Cartridge, during the table creation it complains that one of the ManyToMany table already exists... Does anyone else had an issue with that?
Thanks. Used this snippet with another scenario where there was need to re-create "unmanaged" database tables during tests:
https://gist.github.com/raprasad/f292f94657728de45d1614a741928308
So, how do you use this pattern when you want to test migrations as part of your test suite?
For those who use pytest-django, it already supports commands to define db behaviour on tests:
http://pytest-django.readthedocs.io/en/latest/database.html
You can have a stage env with a different pytest.ini where you test migrations.
Looks like you need to alter this slightly on Django 1.11:
def __getitem__(self, item):
return None
Thanks, it still works 👍
Hello,
Any help please
after running :- ./manage.py test --settings groundup.settings_test
Got this Error :- ModuleNotFoundError: No module named 'notmigrations'
Thanks
If your Django version is >= 1.9
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
MIGRATION_MODULES = DisableMigrations()
Awesome, thanks for this
This is available in Django 3.1 onwards as a setting https://docs.djangoproject.com/en/3.1/ref/settings/#migrate
This is a great tool, but I use the hstore field on some models and the recommend way to install the hstore extension is via a migration: https://docs.djangoproject.com/es/1.9/ref/contrib/postgres/fields/#hstorefield
Any idea how I can run only one migration or run some custom SQL to install the extension?