Skip to content

Instantly share code, notes, and snippets.

@NotSqrt
Forked from nealtodd/settings_test_snippet.py
Last active May 1, 2022 01:34
  • Star 74 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
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()
@Remiz
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?

@raprasad
Copy link

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

@cjw296
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?

@renzon
Copy link

renzon commented Jun 7, 2017

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

@cjw296

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

@tclancy
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

@Jelle28
Copy link

Jelle28 commented Jul 26, 2018

Thanks, it still works 👍

@hmzeh
Copy link

hmzeh commented Jan 11, 2020

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

Thanks

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

@bkane11
Copy link

bkane11 commented Feb 4, 2021

Awesome, thanks for this

@davidkell
Copy link

davidkell commented Jul 26, 2021

This is available in Django 3.1 onwards as a setting https://docs.djangoproject.com/en/3.1/ref/settings/#migrate

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