2015-09-05 53 views
1

我是新Django的開始搞亂了一些事情,看看發生了什麼事會的事情是我有點現在搞砸了,並希望得到幫助。KeyError異常:U「遷移rango.0002_auto_20150905_0345依賴引用不存在的父節點

我手動刪除了一些遷移,然後運行

manage.py squashmigrations app migration_name 

而且改變了一些遷移,然後再次運行該命令。 的事情是我現在面臨的這個小錯誤。最後遷移引用另外一個爲父母但現在不存在。

(kali)[email protected]:~/Poker/tango_with_django_project$ sudo python manage.py migrate  
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
execute_from_command_line(sys.argv) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line 
utility.execute() 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv 
self.execute(*args, **options.__dict__) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute 
output = self.handle(*args, **options) 
    File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 63, in handle 
executor = MigrationExecutor(connection, self.migration_progress_callback) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 17, in __init__ 
self.loader = MigrationLoader(self.connection) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 48, in __init__ 
self.build_graph() 
    File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 237, in build_graph 
self.graph.add_dependency(migration, key, parent) 
    File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/graph.py", line 46, in add_dependency 
"Migration %s dependencies reference nonexistent parent node %r" % (migration, parent) 
KeyError: u"Migration rango.0002_auto_20150905_0345 dependencies reference nonexistent parent node (u'rango', u'0001_squashed_0004_auto_20150904_2325')" 
+0

您是否刪除了遷移文件? – Gocht

+0

@Gocht我做了,現在該如何解決? – Juanvulcano

+0

看到這個http://stackoverflow.com/questions/29355202/accidentally-deleted-my-django-south-migration-directory – Gocht

回答

0
在我的情況

  1. 降分貝(請備份/導出數據)
  2. 刪除遷移文件夾
  3. * pyc文件刪除遷移文件遷移文件夾中,除初始化的.py
  4. 具有相同的名稱
  5. 給privilige用戶數據庫
  6. 創建新的數據庫
  7. Makemigrations
  8. 遷移
  9. Createsuperuser
  10. RUNSERVER

最後,它的工作原理。

+0

thx @Rob重新格式化我的答案;) – gustav