Django Migrate - 找不到父节点

Posted

技术标签:

【中文标题】Django Migrate - 找不到父节点【英文标题】:Django Migrate - can't find a parentnode 【发布时间】:2015-12-17 12:21:18 【问题描述】:

我在尝试修复迁移错误时压缩了我的迁移,它产生了第二个让我感到困惑的错误。

当我尝试迁移我的 heroku 数据库时,我收到此错误:

$ heroku run -a agorafund python manage.py migrate
Running `python manage.py migrate` attached to terminal... up, run.8709
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 294, in build_graph
    _reraise_missing_dependency(migration, parent, e)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 264, in _reraise_missing_dependency
    raise exc
django.db.migrations.graph.NodeNotFoundError: Migration nonprofits.0001_initial dependencies reference nonexistent parent node (u'payments', u'0001_squashed_0026_bankaccount')

最后它说“初始依赖项引用不存在的父节点。(u'payments',u'0001_squashed_0026_bankaccount')”

但是那个节点显然是存在的。 “0001_squashed_0026_bankaccount”存在于我的支付/迁移文件夹中,它没有任何循环依赖。 (就这样开始了:)

class Migration(migrations.Migration):

    replaces = [('payments', '0001_initial'), ('payments', '0002_auto_20150820_2150'), ('payments', '0003_auto_20150823_1507'), ('payments', '0004_auto_20150823_1832'), ('payments', '0005_auto_20150828_1441'), ('payments', '0006_auto_20150828_1559'), ('payments', '0007_remove_product_fee_rate'), ('payments', '0008_product_fee_rate'), ('payments', '0009_remove_product_fee_rate'), ('payments', '0010_recurringpaymentitem'), ('payments', '0010_auto_20150905_2132'), ('payments', '0011_merge'), ('payments', '0012_auto_20150908_2316'), ('payments', '0013_auto_20150910_1517'), ('payments', '0014_paymentitem_recurring'), ('payments', '0015_subscription'), ('payments', '0016_paymentitem_subscription'), ('payments', '0017_userexternalpayconf_livepayment'), ('payments', '0018_auto_20150916_1852'), ('payments', '0019_auto_20150916_1858'), ('payments', '0020_auto_20150916_2210'), ('payments', '0021_auto_20150917_0314'), ('payments', '0022_auto_20150917_1556'), ('payments', '0023_userexternalpayconf_newcreditcard'), ('payments', '0024_auto_20150917_2004'), ('payments', '0025_subscription_paymentitem'), ('payments', '0026_bankaccount')]

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('auth', '0006_require_contenttypes_0002'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

与此同时,非营利组织的初始迁移是这样开始的:

类迁移(migrations.Migration):

dependencies = [
    ('payments', '0001_squashed_0026_bankaccount'),
]

有什么想法吗?

【问题讨论】:

也有这个迁移('payments', '0026_bankaccount')? 【参考方案1】:

删除迁移(migrations/ 中的所有内容,当然 __init__.py 除外)为我解决了这个问题。来自这个 Stack Overflow 答案的建议:

如果找不到丢失的迁移文件,则必须删除 并为应用程序重新创建迁移,以便它们不依赖于 失踪的迁移。 https://***.com/a/33676462/1762493

【讨论】:

以上是关于Django Migrate - 找不到父节点的主要内容,如果未能解决你的问题,请参考以下文章

django 找不到新的 sqlite 版本? (需要 SQLite 3.8.3 或更高版本(找到 3.7.17))

syncdb 和 migrate 有啥区别?

django找不到新的sqlite版本? (需要SQLite 3.8.3或更高版本(找到3.7.17))

php artisan migrate:[PDOException] 找不到驱动程序

找不到QT的头文件怎么办?

Laravel:PHP Artisan Migrate 抛出 PDO 异常:找不到驱动程序(Postgres)