#21969 closed Bug (fixed)

Dependent apps do not handle fixture data properly when migration

Reported by: Ubercore Owned by: Andrew Godwin <andrew@…>
Component: Migrations Version: master
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have app_a , and app_b . app_a lists app_b as a dependency, and app_b has a fixture in initial_data.json . When I run ./manage.py migrate , the dependency is resolved correctly, and app_b is migrated first. However, it seems that the fixture tries to load before the table exists:

$ ./manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: evolve, pipeline, mptt, sessions, admin, suit_redactor, sites, auth, reversion, contenttypes, django_extensions, taggit, suit, easy_thumbnails
  Apply all migrations: content, translation, sites, auth
Synchronizing apps without migrations:
  Creating tables...
    Creating table django_admin_log
    Creating table auth_permission
    Creating table auth_group_permissions
    Creating table auth_group
    Creating table auth_user_groups
    Creating table auth_user_user_permissions
    Creating table auth_user
    Creating table django_content_type
    Creating table django_session
    Creating table django_site
    Creating table easy_thumbnails_source
    Creating table easy_thumbnails_thumbnail
    Creating table reversion_revision
    Creating table reversion_version
    Creating table taggit_tag
    Creating table taggit_taggeditem
  Installing custom SQL...
  Installing indexes...
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/ENV/src/django/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/ENV/src/django/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/ENV/src/django/django/core/management/base.py", line 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/ENV/src/django/django/core/management/base.py", line 336, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/migrate.py", line 125, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/migrate.py", line 281, in sync_apps
    call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=connection.alias, skip_validation=True)
  File "/home/vagrant/ENV/src/django/django/core/management/__init__.py", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/home/vagrant/ENV/src/django/django/core/management/base.py", line 336, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/loaddata.py", line 56, in handle
    self.loaddata(fixture_labels)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/loaddata.py", line 85, in loaddata
    self.load_label(fixture_label)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/loaddata.py", line 140, in load_label
    obj.save(using=self.using)
  File "/home/vagrant/ENV/src/django/django/core/serializers/base.py", line 172, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/home/vagrant/ENV/src/django/django/db/models/base.py", line 630, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/vagrant/ENV/src/django/django/db/models/base.py", line 692, in _save_table
    forced_update)
  File "/home/vagrant/ENV/src/django/django/db/models/base.py", line 736, in _do_update
    return filtered._update(values) > 0
  File "/home/vagrant/ENV/src/django/django/db/models/query.py", line 595, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/vagrant/ENV/src/django/django/db/models/sql/compiler.py", line 991, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/home/vagrant/ENV/src/django/django/db/models/sql/compiler.py", line 779, in execute_sql
    cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/utils.py", line 77, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/utils.py", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/utils.py", line 93, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/vagrant/ENV/src/django/django/db/backends/utils.py", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/sqlite3/base.py", line 494, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: Problem installing fixture '/home/vagrant/seie/translation/fixtures/initial_data.json': Could not load translation.Language(pk=1): no such table: translation_language

In the example above, app_a is content, and app_b is translation. Also note that this example is run immediately after a reset_db

Change History (5)

comment:1 Changed 18 months ago by Ubercore

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Bug

comment:2 Changed 18 months ago by Ubercore

  • Needs tests set

comment:3 Changed 18 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 18 months ago by andrewgodwin

This bug is actually that initial_data shouldn't be loaded at all for apps with migrations, it's been deprecated (if you want to load initial data it's now suggested to use the RunPython operation and do it using the ORM).

I'll fix it so initial_data is only run for unmigrated apps.

comment:5 Changed 18 months ago by Andrew Godwin <andrew@…>

  • Owner set to Andrew Godwin <andrew@…>
  • Resolution set to fixed
  • Status changed from new to closed

In d5df7a0515b08621a526a9c9ffde7d7702c5b07e:

Fixed #21969: Fix behaviour of initial_data with migrated apps

Note: See TracTickets for help on using tickets.
Back to Top