Disable migrations when running unit tests in Django 1.7

后端 未结 7 1136
一向
一向 2020-11-30 19:57

Django 1.7 introduced database migrations.

When running the unit tests in Django 1.7, it forces a migrate, that takes a long time. So I woul

相关标签:
7条回答
  • 2020-11-30 20:54

    I just figure out how to disable migrations after django 1.10,may be it could help for somebody. Here is link at git

    class DisableMigrations(dict):
        def __contains__(self, item):
            return True
    
        def __getitem__(self, item):
            return None
    
    DATABASES = DisableMigrations()
    
    MIGRATION_MODULES = DisableMigrations()
    

    Migrations for django 1.10 has two part,please look at load_disk and recorder

    The part of load_disk for migrations model of app that be added at INSTALL_APP And the part of recorder for database connection For the version before 1.9 we need set MIGRATION_MODULES={'do.not.migrate':'notmigrations'} when you are running test Now we need set it None like MIGRATION_MODULES={'do.not.migrate':None} So if we do not want make migrations for any app, just extend a dict and return None for getitem function , and do the same at DATABASES, that is the right thing you need to do

    PS: For command, you need to specify --setting=module.path.settings_test_snippet after test PPS If you are working with pycharm ,do not set --settings options at Run/Debug configurations, just add path of settings_test_snippet.py at Custom setting. That just be fine!!

    enjoy

    0 讨论(0)
提交回复
热议问题