Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Another shot at this problem ..
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return "notmigrations"
MIGRATION_MODULES = DisableMigrations()
Copy link

rchrd2 commented Dec 11, 2014

This worked for me, and it is more simple than other solutions I came accross.

Copy link

danxshap commented Dec 15, 2014

Thank you for this!

Copy link

rikva commented Dec 17, 2014

Perfect. Thanks!

Copy link

chrisbarmonde commented Jan 15, 2015

You are a patron saint of testing.

Copy link

runekaagaard commented Jan 23, 2015

One word: Ahhhhhhhhh

Copy link

jordij commented Feb 4, 2015


Copy link

maximiliano commented Feb 19, 2015

Worked better for me, thanks!

Copy link

LegoStormtroopr commented Mar 1, 2015

+1 love it.

Copy link

LeMeteore commented Mar 4, 2015

Thanks a lot, +10000

Copy link

troygrosfield commented Apr 19, 2015

Just so everyone can support the publicly release app by @henriquebastos that includes this snippet:

Should rename the app to "headache reliever". Thanks guys! 👍

Copy link

mannysz commented May 7, 2015

Is there a way to use it with django-nose?

Copy link

NotSqrt commented Jul 7, 2015

Glad I could help 😃

Copy link

adrienemery commented Jul 22, 2015

Has anyone used this with django-nose?

Copy link

flaugher commented Sep 20, 2015

Could someone please explain exactly how you use this snippet when running your tests? Thank you.

Copy link

chrisv2 commented Jan 23, 2016

@flaugher: create a next to your regular

import * from settings
# snippet content goes here

Then run your tests with settings_test instead of regular settings: test --settings mysite.settings_test [test spec]

Copy link

nicholasserra commented Feb 18, 2016


Copy link

jamescw commented Feb 25, 2016

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:

Any idea how I can run only one migration or run some custom SQL to install the extension?

Copy link

roblinton commented Mar 1, 2016


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()

Copy link

Remiz commented Aug 3, 2016

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?

Copy link

raprasad commented Aug 12, 2016

Thanks. Used this snippet with another scenario where there was need to re-create "unmanaged" database tables during tests:

Copy link

cjw296 commented Oct 7, 2016

So, how do you use this pattern when you want to test migrations as part of your test suite?

Copy link

renzon commented Jun 7, 2017

For those who use pytest-django, it already supports commands to define db behaviour on tests:


You can have a stage env with a different pytest.ini where you test migrations.

Copy link

tclancy commented Oct 27, 2017

Looks like you need to alter this slightly on Django 1.11:

def __getitem__(self, item):
        return None

Copy link

Jelle28 commented Jul 26, 2018

Thanks, it still works 👍

Copy link

hmzeh commented Jan 11, 2020

Any help please
after running :- ./ test --settings groundup.settings_test
Got this Error :- ModuleNotFoundError: No module named 'notmigrations'


Copy link

mariuccio commented Jan 30, 2020

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()

Copy link

bkane11 commented Feb 4, 2021

Awesome, thanks for this

Copy link

davidkell commented Jul 26, 2021

This is available in Django 3.1 onwards as a setting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment