Opened 4 months ago

Last modified 4 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

Description

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:

MIGRATION_MODULES = {}
for app in INSTALLED_APPS:
    if app.startswith('django.contrib.'):
        app=app.replace('django.contrib.', '')
    MIGRATION_MODULES[app] = None

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 django.db.backends.creation.py (lines 64 to 70) from

    call_command(
            'migrate',
            verbosity=max(verbosity - 1, 0),
            interactive=False,
            database=self.connection.alias,
            run_syncdb=true,
        )

To

    call_command(
            'migrate',
            verbosity=max(verbosity - 1, 0),
            interactive=False,
            database=self.connection.alias,
            run_syncdb=not keepdb,
        )

Change History (3)

comment:8 Changed 4 months ago by Tim Graham

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

comment:10 Changed 4 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 settings.py

    MIGRATION_MODULES = DisableMigrations()

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

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