Запуск мои тесты после раздавливания миграции Я получаю сообщение об ошибке:У миграции Django у build_graph есть ошибка?
lib/python2.7/site-packages/django/db/migrations/loader.py:220: KeyError
Вот исходный код:
def build_graph(self):
"""
Builds a migration dependency graph using both the disk and database.
You'll need to rebuild the graph if you apply migrations. This isn't
usually a problem as generally migration stuff runs in a one-shot process.
"""
# Load disk data
self.load_disk()
# Load database data
if self.connection is None:
self.applied_migrations = set()
else:
recorder = MigrationRecorder(self.connection)
self.applied_migrations = recorder.applied_migrations()
# Do a first pass to separate out replacing and non-replacing migrations
normal = {}
replacing = {}
for key, migration in self.disk_migrations.items():
if migration.replaces:
replacing[key] = migration
else:
normal[key] = migration
# Calculate reverse dependencies - i.e., for each migration, what depends on it?
# This is just for dependency re-pointing when applying replacements,
# so we ignore run_before here.
reverse_dependencies = {}
for key, migration in normal.items():
for parent in migration.dependencies:
reverse_dependencies.setdefault(parent, set()).add(key)
# Carry out replacements if we can - that is, if all replaced migrations
# are either unapplied or missing.
for key, migration in replacing.items():
# Ensure this replacement migration is not in applied_migrations
self.applied_migrations.discard(key)
# Do the check. We can replace if all our replace targets are
# applied, or if all of them are unapplied.
applied_statuses = [(target in self.applied_migrations) for target in migration.replaces]
can_replace = all(applied_statuses) or (not any(applied_statuses))
if not can_replace:
continue
# Alright, time to replace. Step through the replaced migrations
# and remove, repointing dependencies if needs be.
for replaced in migration.replaces:
if replaced in normal:
# We don't care if the replaced migration doesn't exist;
# the usage pattern here is to delete things after a while.
del normal[replaced]
for child_key in reverse_dependencies.get(replaced, set()):
if child_key in migration.replaces:
continue
normal[child_key].dependencies.remove(replaced)
Последняя строка бросает это:
KeyError: ('my_app', u'0001_initial')
Вы видите проблему заключается в том, что child_key
нет в словаре normal
. В предыдущей строке проверяется, находится ли child_key в migrations.replaces, потому что в этом случае возможно, что миграции child_key уже удалены. Однако возможно, что child_key находится в замене другого переноса и, следовательно, в любом случае его можно было бы удалить, даже если он не находится в mig.replaces.
Вы согласны с этим является ошибкой в коде django?
У меня такая же проблема. Я раздавил несколько приложений и внезапно начал получать эту ошибку. Я попытаюсь отладить его, полагая, что проблема находится в последнем пристроенном приложении. – gepatino