[Django] #29039: Disabling migrations doesn't work with --keepdb

16 views
Skip to first unread message

Django

unread,
Jan 19, 2018, 7:58:43 AM1/19/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar | Owner: nobody
Afzal |
Type: | Status: new
Uncategorized |
Component: | Version: 1.11
Migrations | Keywords: database, tests,
Severity: Normal | migrations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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,
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29039>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 26, 2018, 9:09:38 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anoosha keen):

* owner: nobody => Anoosha keen
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:1>

Django

unread,
Jan 26, 2018, 9:59:07 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anoosha keen):

**I get this error:**
if name.startswith('.'):
AttributeError: 'NoneType' object has no attribute 'startswith'
When I add the given code to setting.py I got the error mentioned
above.Can you explain this please?
Replying to [ticket:29039 Vackar Afzal]:

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:2>

Django

unread,
Jan 26, 2018, 10:20:15 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Vackar Afzal):

Replying to [comment:2 Anoosha keen]:


> **I get this error:**
> if name.startswith('.'):
> AttributeError: 'NoneType' object has no attribute 'startswith'
> When I add the given code to setting.py I got the error mentioned
above.Can you explain this please?


What output do you get from either:
print INSTALLED_APPS #Python2.x
or
print (INSTALLED_APPS) #Python3.x

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:3>

Django

unread,
Jan 26, 2018, 11:07:46 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Anoosha keen):

**Output is this:**
python manage.py runserver
None
None
None
None
None
None
None
None
None
None
None
None
None
None
Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function
check_errors.<locals>.wrapper at 0x7f570f8098c8>
Traceback (most recent call last):
File "/home/anoosha/django/django/utils/autoreload.py", line 220, in
wrapper
fn(*args, **kwargs)
File
"/home/anoosha/django/django/core/management/commands/runserver.py", line
113, in inner_run
self.check_migrations()
File
"/home/anoosha/django/django/core/management/commands/runserver.py", line
159, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/home/anoosha/django/django/db/migrations/executor.py", line 19,
in __init__
self.loader = MigrationLoader(self.connection)
File "/home/anoosha/django/django/db/migrations/loader.py", line 49, in
__init__
self.build_graph()
File "/home/anoosha/django/django/db/migrations/loader.py", line 178, in
build_graph
self.load_disk()
File "/home/anoosha/django/django/db/migrations/loader.py", line 71, in
load_disk
module = import_module(module_name)
File
"/home/anoosha/.virtualenvs/djangodev/lib/python3.5/importlib/__init__.py",
line 117, in import_module


if name.startswith('.'):
AttributeError: 'NoneType' object has no attribute 'startswith'

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:4>

Django

unread,
Jan 26, 2018, 11:14:53 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anoosha keen):

* cc: Anoosha keen (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:5>

Django

unread,
Jan 26, 2018, 11:19:44 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Vackar Afzal):

Could you please add the print statement before the custom block of code

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:6>

Django

unread,
Jan 26, 2018, 11:26:52 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Is `/home/anoosha/django` using Django's master branch? The traceback
shows line numbers that makes me think it's not.

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:7>

Django

unread,
Jan 26, 2018, 11:31:24 AM1/26/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: Anoosha
| keen
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Migrations => Testing framework
* type: Uncategorized => Bug
* easy: 1 => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:8>

Django

unread,
Jan 30, 2018, 6:18:50 AM1/30/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: (none)
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anoosha keen):

* owner: Anoosha keen => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:9>

Django

unread,
Jan 30, 2018, 8:32:08 AM1/30/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: (none)
Type: Bug | Status: new
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (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()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:10>

Django

unread,
Feb 2, 2018, 3:06:42 AM2/2/18
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: nobody

Type: Bug | Status: new
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: database, tests, | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Davor Lučić):

* cc: Davor Lučić (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:11>

Django

unread,
Dec 5, 2019, 4:31:05 AM12/5/19
to django-...@googlegroups.com
#29039: Disabling migrations doesn't work with --keepdb
-------------------------------------+-------------------------------------
Reporter: Vackar Afzal | Owner: nobody
Type: Bug | Status: closed
Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: database, tests, | Triage Stage: Accepted
migrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* version: 1.11 => master
* resolution: => fixed


Comment:

This should be fixed in Django 3.1 by using the new
[https://docs.djangoproject.com/en/dev/ref/settings/#migrate MIGRATE] test
database setting that allows disabling of migrations during a test
database creation (see #25388).

Fixed in f5ebdfce5c417f9844e86bccc2f12577064d4bad.

--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:12>

Reply all
Reply to author
Forward
0 new messages