Opened 10 years ago

Closed 10 years ago

#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: dev
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


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 ./ 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:

$ ./ 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 "./", line 10, in <module>
  File "/home/vagrant/ENV/src/django/django/core/management/", line 427, in execute_from_command_line
  File "/home/vagrant/ENV/src/django/django/core/management/", line 419, in execute
  File "/home/vagrant/ENV/src/django/django/core/management/", line 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/ENV/src/django/django/core/management/", line 336, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/", line 125, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/", 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/", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/home/vagrant/ENV/src/django/django/core/management/", line 336, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/ENV/src/django/django/core/management/commands/", line 56, in handle
  File "/home/vagrant/ENV/src/django/django/core/management/commands/", line 85, in loaddata
  File "/home/vagrant/ENV/src/django/django/core/management/commands/", line 140, in load_label
  File "/home/vagrant/ENV/src/django/django/core/serializers/", line 172, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/home/vagrant/ENV/src/django/django/db/models/", 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/", line 692, in _save_table
  File "/home/vagrant/ENV/src/django/django/db/models/", line 736, in _do_update
    return filtered._update(values) > 0
  File "/home/vagrant/ENV/src/django/django/db/models/", line 595, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/vagrant/ENV/src/django/django/db/models/sql/", line 991, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/home/vagrant/ENV/src/django/django/db/models/sql/", line 779, in execute_sql
    cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/", line 77, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/", line 93, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/vagrant/ENV/src/django/django/db/backends/", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/home/vagrant/ENV/src/django/django/db/backends/sqlite3/", 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 10 years ago by Ubercore

Type: UncategorizedBug

comment:2 Changed 10 years ago by Ubercore

Needs tests: set

comment:3 Changed 10 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

comment:4 Changed 10 years ago by Andrew Godwin

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 10 years ago by Andrew Godwin <andrew@…>

Owner: set to Andrew Godwin <andrew@…>
Resolution: fixed
Status: newclosed

In d5df7a0515b08621a526a9c9ffde7d7702c5b07e:

Fixed #21969: Fix behaviour of initial_data with migrated apps

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