{{{
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.
* owner: nobody => Anoosha keen
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:1>
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>
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>
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>
* cc: Anoosha keen (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:5>
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>
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>
* component: Migrations => Testing framework
* type: Uncategorized => Bug
* easy: 1 => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:8>
* owner: Anoosha keen => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:9>
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>
* cc: Davor Lučić (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29039#comment:11>
* 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>