django.db.migrations.exceptions.NodeNotFoundError:迁移accounts.0001_initial依赖项引用不存在的父节点 [英] django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node

查看:32
本文介绍了django.db.migrations.exceptions.NodeNotFoundError:迁移accounts.0001_initial依赖项引用不存在的父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 heroku 上部署我的项目,我使用的是 django 3.1,但我无法做到这一点.由于迁移,我收到错误消息.请我谦虚地请求您给这个问题一些时间来解决这个问题.每当我运行命令 heroku run python manage.py migrate 时,它都会给出以下回溯.

I'm trying to deploy my project on heroku ,i'm using django 3.1 and i'm unable to do that. I'm getting error due to migrations. Please i humble request you to give some time to this question to resolve this problem. Whenever i run the command heroku run python manage.py migrate ,it gives following traceback.

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 92, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 255, in build_graph
    self.graph.validate_consistency()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/graph.py", line 195, in validate_consistency
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/graph.py", line 195, in <listcomp>
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/graph.py", line 58, in raise_error
    raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node ('auth', '0023_remove_user_current_balance')

迁移依赖

 dependencies = [
        ('auth', '0023_remove_user_current_balance'),
    ]

账户模型

GENDER_CHOICES = (
    ('male','Male'),
    ('female','Female'),
    )
class User(auth.models.AbstractUser):
    
    current_balance = models.IntegerField(("user balance"),default=0, blank=True, null=True)
    age = models.IntegerField(("age"),blank=True, null=True)
    gender = models.CharField(("gender"), max_length=50,choices=GENDER_CHOICES,null=True)
    nationality = models.CharField(("nationality"), max_length=50,null=True)

    def __str__(self):
        return "@{}".format(self.username)

当我尝试注释掉依赖项时,它返回给我:raise ValueError('Related model %r cannot beresolution' % self.remote_field.model)ValueError: Related model 'auth.Group' cannot be已解决

When i tried to comment out the dependency , Then it returned me : raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)ValueError: Related model 'auth.Group' cannot be resolved

如果需要更多代码,请在评论部分告诉我谢谢.

if more code is require then tell me in a comment section thank you.

推荐答案

如果您删除一些过去的迁移,则可能会发生这种情况.所有迁移都会创建一个图(树状结构).您只需要确保其中没有悬挂的分支,这些分支会导致上一个不再属于树的分支.你可以把它放在纸上进行可视化.

This may happen if you remove some of past migration. All migrations create a graph (tree like structure). You just have to make sure there is no hanging branches in it that lead to previous branch that is not part of the tree anymore. You may put it on the paper to visualise it.

修复将是:

  1. 从列表中删除依赖项在分支的情况下:

假设附属应用已被删除(及其迁移)

Let's say affiliate app is deleted (with its migrations)

dependencies = [
    ('affiliate', '0003_remove_affiliateaccount_project'),
    ('partner', '0073_auto_20191008_1705'),
]

解决办法:

dependencies = [
    ('partner', '0073_auto_20191008_1705'),
]

  1. 指向不同的端点

  1. To point it on different endpoint

依赖项 = [('auth', '0023_remove_user_current_balance'),]

dependencies = [ ('auth', '0023_remove_user_current_balance'), ]

解决办法:

dependencies = [
    ('partner', 'XXXX_head_that_exists_YYYYMMDD_XXXX'),
]

这篇关于django.db.migrations.exceptions.NodeNotFoundError:迁移accounts.0001_initial依赖项引用不存在的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆