Opened 12 months ago

Last modified 12 months ago

#29039 new Bug

Disabling migrations doesn't work with --keepdb

Reported by: Vackar Afzal Owned by: nobody
Component: Testing framework Version: 1.11
Severity: Normal Keywords: database, tests, migrations
Cc: Davor Lučić Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


We have a large number of migrations in our application now, and as a result it can take 20 mins to create a test DB.
To make this faster I am settings MIGRATION_MODULES in my settings as follows:

for app in INSTALLED_APPS:
    if app.startswith('django.contrib.'):
        app=app.replace('django.contrib.', '')

I've found that this breaks the --keepdb option as it Django wants to run sync_db internally every time.

The workaround I found is to modify (lines 64 to 70) from

            verbosity=max(verbosity - 1, 0),


            verbosity=max(verbosity - 1, 0),
            run_syncdb=not keepdb,

Change History (3)

comment:8 Changed 12 months ago by Tim Graham

Component: MigrationsTesting framework
Easy pickings: unset
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:10 Changed 12 months ago by Sergey Yurchenko

I have the same problems with creation of test db.
For tests I don`t use migrations but models directly like in older versions of Django without migrations.
Tests with migrations run is CI to check that migrations are correct so nobody cares about time.

class DisableMigrations(object):
    def __contains__(self, item):
        return True

    def __getitem__(self, item):
        return None

in your

    MIGRATION_MODULES = DisableMigrations()

comment:11 Changed 12 months ago by Davor Lučić

Cc: Davor Lučić added
Note: See TracTickets for help on using tickets.
Back to Top