Opened 9 years ago

Last modified 9 years ago

#24628 closed Bug

Cannot apply migration that depends on squashed migration — at Initial Version

Reported by: Martin Häcker Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After some time in the chat with MarkusH, we decided that this should be a bug report.

Some context: I have quite some migrations (33) of which the first already was a squash of several migrations. It did get it's 'replaced' field removed though, as the original migrations it replaced are long gone already. The goal now was to get that long list of migrations down to one again, for peace of mind.

This led to the following symptoms: When I created the squashed migration everything seemed fine. ./manage.py migrate did say that nothing was to be done (but then again, all the migrations to be squashed where already applied).

But adding another migration after that ended in tears - ./manage migrate didn't want to apply it and told me so in no uncertain terms.

(pycess)dwt@atlan ~/Code/Projekte/pycess/pycess (git)-[master] % ./manage.py migrate
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/dwt/Code/Projekte/pycess/django/django/core/management/__init__.py", line 330, in execute_from_command_line
    utility.execute()
  File "/Users/dwt/Code/Projekte/pycess/django/django/core/management/__init__.py", line 322, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/dwt/Code/Projekte/pycess/django/django/core/management/base.py", line 347, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/dwt/Code/Projekte/pycess/django/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/Users/dwt/Code/Projekte/pycess/django/django/core/management/commands/migrate.py", line 86, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/loader.py", line 281, in build_graph
    _reraise_missing_dependency(migration, parent, e)
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/loader.py", line 264, in _reraise_missing_dependency
    raise exc
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/loader.py", line 274, in build_graph
    self.graph.add_dependency(migration, key, parent)
  File "/Users/dwt/Code/Projekte/pycess/django/django/db/migrations/graph.py", line 124, in add_dependency
    parent
django.db.migrations.graph.NodeNotFoundError: Migration process.0002_auto_20150411_1005 dependencies reference nonexistent parent node ('process', '0001_squashed_initial_2')

Here we had quite some discussion in #django-dev with MarkusH, of which the result to me was that a) django doesn't seem to ever record that a squashed migration is applied, at least as long as it is recognizable by django as a squashed migration (i.e. it has a .replaced property). b) there seems to be no way to tell django that the replacing squashed migration really is already applied for this database.

The last one turned out to be achievable if you remove the old migrations and the .replaces property from the squashed migration and then apply it with --fake

MarkusH might want to say more here that he can describe better.

For ease of reproduction I'm attaching the project where this occurred for me.

Change History (0)

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