Opened 7 years ago
Closed 5 years ago
#29039 closed Bug (fixed)
Disabling migrations doesn't work with --keepdb
Reported by: | Vackar Afzal | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
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 (4)
comment:8 by , 7 years ago
Component: | Migrations → Testing framework |
---|---|
Easy pickings: | unset |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:10 by , 7 years ago
comment:11 by , 7 years ago
Cc: | added |
---|
comment:12 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Version: | 1.11 → master |
This should be fixed in Django 3.1 by using the new MIGRATE test database setting that allows disabling of migrations during a test database creation (see #25388).
Fixed in f5ebdfce5c417f9844e86bccc2f12577064d4bad.
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.
in your settings.py