[英]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:修复将是:
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'),
]
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.