Opened 3 years ago

Closed 2 years ago

#22263 closed Bug (invalid)

KeyError: 'to' in MigrationAutodetector with uncommon setup (django-taggit)

Reported by: Daniel Hahler Owned by: nobody
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: mszamot@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


I am getting a KeyError exception, when running migrate a second time on a Django 1.7 project (fresh DB, but migrated from 1.6).

It seems like Django expects a key "to" in the field's deconstructor, which is not provided by the deconstructor.


% migrate
Operations to perform:
  Synchronize unmigrated apps: djsupervisor, autocomplete_light, reversion, sessions, admin, grappelli, sites, auth, compressor, contenttypes, django_extensions, template_debug, sekizai, django_pdb, crispy_forms
  Apply all migrations: contenttypes, test_duration, taggit
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations needed.
Traceback (most recent call last):
  File "/home/user/.virtualenvs/tmm/bin/", line 25, in <module>
  File "…/django-master/django/core/management/", line 427, in execute_from_command_line
  File "…/django-master/django/core/management/", line 419, in execute
  File "…/django-master/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "…/django-master/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "…/django-master/django/core/management/commands/", line 140, in handle
    changes = autodetector.changes(graph=executor.loader.graph)
  File "…/django-master/django/db/migrations/", line 33, in changes
    changes = self._detect_changes()
  File "…/django-master/django/db/migrations/", line 84, in _detect_changes
    model_fields_def = _rel_agnostic_fields_def(model_state.fields)
  File "…/django-master/django/db/migrations/", line 74, in _rel_agnostic_fields_def
    del deconstruction[2]['to']
KeyError: 'to'

I have tried to add a testcase for this, but failed - I've stopped when it got too bloated.. :/
There should be one added probably to tests/migrations/

I had reported the issue initially at:

Change History (5)

comment:1 Changed 3 years ago by Daniel Hahler

Needs documentation: unset
Needs tests: set
Patch needs improvement: unset

Here is a pull request:

NOTE: I am not sure, if this is a bug with django-taggit instead, which should have returned to in its deconstruction (since it has setup).

comment:2 Changed 3 years ago by Marcin Szamotulski <mszamot@…>

Cc: mszamot@… added

I can reproduce it here, and indeed this will fix the problem.

comment:3 Changed 3 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

comment:4 Changed 2 years ago by Tim Graham

Easy pickings: unset

comment:5 Changed 2 years ago by Markus Holtermann

Resolution: invalid
Status: newclosed

This issue was django-taggit related and not a problem in Django itself. Has been fixed in

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