Create a gist now

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()
rchrd2 commented Dec 11, 2014

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

Thank you for this!

rikva commented Dec 17, 2014

Perfect. Thanks!

You are a patron saint of testing.

One word: Ahhhhhhhhh

jordij commented Feb 4, 2015

boss!

Worked better for me, thanks!

+1 love it.

Thanks a lot, +10000

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

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

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

Owner
NotSqrt commented Jul 7, 2015

Glad I could help 😃

Has anyone used this with django-nose?

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

chrisv2 commented Jan 23, 2016

@flaugher: create a settings_test.py next to your regular settings.py:

import * from settings
# snippet content goes here

Then run your tests with settings_test instead of regular settings:

manage.py test --settings mysite.settings_test [test spec]

Thanks!

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: 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?

@jamescw,

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

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 commented Oct 7, 2016

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

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