我尝试在heroku上部署我的项目,我使用的是django 3.1,我无法做到这一点。我得到错误,由于迁移。请我谦卑的请求您给予一些时间来解决这个问题。每当我运行命令heroku run 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')
迁移依赖性
dependencies = [
('auth', '0023_remove_user_current_balance'),
]
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)
当我试图注解掉依赖项时,它返回给我:引发值错误("无法解析相关模型%r“% self.remote_field.model)值错误:无法解析相关模型“授权组”
如果需要更多代码,请在注解部分告诉我,谢谢。
2条答案
按热度按时间uurv41yg1#
我也遇到了同样的问题,就是因为迁移历史不一致,所以我删除了所有已安装应用的迁移目录,然后调用
python manage.py makemigrations
命令,新的迁移没有问题。wb1gzix02#
如果您删除了一些过去的迁移,则可能会发生这种情况。所有迁移都会创建一个图形(树状结构)。您只需确保其中没有悬挂的分支,这些分支会导致不再是树的一部分的前一个分支。您可以将其放在纸上以使其可视化。
修复方法为:
1.若要在分支 * 的情况下从清单 * 中移除相依性:
假设附属应用程序已删除(包括其迁移)
解决方案:
1.将其指向不同端点
用户名和密码
解决方法: