﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23031	Django 1.7.x test failing for application with migrations and initial data	linovia	nobody	"It seems commit 0dd737a719cfbd3bc11ff6f2b90161883fcebea0 introduced a regression in the following case:
- the application has migrations
- the application has initial_data

With this configuration Django will crash before any test is run.
This is caused by the initial_data being loaded at the end of the flush while the migrations did not create the associated tables yet:

{{{
(django17_test) air-de-xavier:demo xordoquy$ python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
  File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py"", line 385, in execute_from_command_line
    utility.execute()
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py"", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py"", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py"", line 71, in execute
    super(Command, self).execute(*args, **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/test.py"", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py"", line 147, in run_tests
    old_config = self.setup_databases()
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py"", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/test/runner.py"", line 299, in setup_databases
    serialize=connection.settings_dict.get(""TEST_SERIALIZE"", True),
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/backends/creation.py"", line 374, in create_test_db
    test_flush=True,
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py"", line 115, in call_command
    return klass.execute(*args, **defaults)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/migrate.py"", line 141, in handle
    inhibit_post_migrate=True,
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py"", line 115, in call_command
    return klass.execute(*args, **defaults)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 532, in handle
    return self.handle_noargs(**options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/flush.py"", line 85, in handle_noargs
    call_command('loaddata', 'initial_data', **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/__init__.py"", line 115, in call_command
    return klass.execute(*args, **defaults)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/base.py"", line 337, in execute
    output = self.handle(*args, **options)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py"", line 60, in handle
    self.loaddata(fixture_labels)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py"", line 90, in loaddata
    self.load_label(fixture_label)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/management/commands/loaddata.py"", line 147, in load_label
    obj.save(using=self.using)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/core/serializers/base.py"", line 173, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/base.py"", line 618, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/base.py"", line 680, in _save_table
    forced_update)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/base.py"", line 724, in _do_update
    return filtered._update(values) > 0
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/query.py"", line 598, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/sql/compiler.py"", line 1003, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/models/sql/compiler.py"", line 785, in execute_sql
    cursor.execute(sql, params)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/backends/utils.py"", line 65, in execute
    return self.cursor.execute(sql, params)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/utils.py"", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/backends/utils.py"", line 65, in execute
    return self.cursor.execute(sql, params)
  File ""/Users/xordoquy/.virtualenvs/django17_test/lib/python2.7/site-packages/Django-1.7c1-py2.7.egg/django/db/backends/sqlite3/base.py"", line 485, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: Problem installing fixture '/Users/xordoquy/django17_test/demo/demo/core/fixtures/initial_data.json': Could not load core.Bug(pk=1): no such table: core_bug
(django17_test) air-de-xavier:demo xordoquy$ 
}}}"	Bug	closed	Migrations	1.7-rc-1	Normal	invalid		linovia	Accepted	0	0	0	0	0	0
