简体   繁体   English

django.db.migrations.exceptions.NodeNotFoundError:迁移accounts.0001_initial依赖项引用不存在的父节点

[英]django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node

I'm trying to deploy my project on heroku,i'm using django 3.1 and i'm unable to do that.我正在尝试在 heroku 上部署我的项目,我正在使用 django 3.1,但我无法做到这一点。 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.每当我运行命令heroku 运行 python manage.py migrate时,它都会给出以下回溯。

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')

migration dependency迁移依赖

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

account.model account.model

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)

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当我试图注释掉依赖项时,它返回给我: 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.如果需要更多代码,请在评论部分告诉我谢谢。

I had the same problem.我有同样的问题。 It is because of the inconsistent migration history.这是因为迁移历史不一致。 So I deleted the migrations directory in all installed apps and then called python manage.py makemigrations command.所以我删除了所有已安装应用程序中的迁移目录,然后调用python manage.py makemigrations命令。 The new migrations had no problem.新的迁移没有问题。

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.你可以把它放在纸上以可视化它。

Fix would be:修复将是:

  1. To remove dependency from the list in case of branch :在分支的情况下从列表中删除依赖项:

Let's say affiliate app is deleted (with its migrations)假设附属应用程序被删除(及其迁移)

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

solution:解决方案:

dependencies = [
    ('partner', '0073_auto_20191008_1705'),
]
  1. To point it on different endpoint将其指向不同的端点

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

solution:解决方案:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django.db.migrations.exceptions.InconsistentMigrationHistory:迁移在其依赖accounts.0001_initial之前应用在数据库'default'上 - django.db.migrations.exceptions.InconsistentMigrationHistory: Migration is applied before its dependency accounts.0001_initial on database 'default' 删除迁移文件并获取 django.db.migrations.exceptions.NodeNotFoundError: - Deleting Migration Files and Getting django.db.migrations.exceptions.NodeNotFoundError: django.db.migrations.exceptions.NodeNotFoundError - django.db.migrations.exceptions.NodeNotFoundError Django 迁移 - django.db.migrations.exceptions.NodeNotFoundError - Django migrations - django.db.migrations.exceptions.NodeNotFoundError Django 迁移 - 依赖项引用不存在的父节点 - Django Migrations - Dependencies reference nonexistent parent node 自定义 django 数据迁移创建记录 allauth.account EmailAddress model 返回错误 - django.db.migrations.exceptions.NodeNotFoundError: - Custom django data migration creating records allauth.account EmailAddress model returns error - django.db.migrations.exceptions.NodeNotFoundError: django.db.migrations.exceptions.NodeNotFoundError:迁移 app.0172_auto_20220603_1746 依赖 _auto_20220601_2313&#39;) - django.db.migrations.exceptions.NodeNotFoundError: Migration app.0172_auto_20220603_1746 dependencie _auto_20220601_2313') 我的项目中没有名为“帐户”的应用程序,但 django 仍然抛出 django.db.migrations.exceptions.NodeNotFoundError - No app named 'account' in my project but django still throws django.db.migrations.exceptions.NodeNotFoundError django.db.migrations.exceptions.NodeNotFoundError:运行“python manage.py migrate”时 - django.db.migrations.exceptions.NodeNotFoundError: upon running "python manage.py migrate" 在命令提示符下运行服务器时出现 django.db.migrations.exceptions.NodeNotFoundError - django.db.migrations.exceptions.NodeNotFoundError when running the server in command prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM