gpt4 book ai didi

python - Django 类型错误 : allow_migrate() got an unexpected keyword argument 'model_name'

转载 作者:可可西里 更新时间:2023-11-01 07:21:55 25 4
gpt4 key购买 nike

所以我将我的 Django 项目复制到一个新服务器,复制了环境并将表导入到本地 mysql 数据库。

但是当我尝试运行 makemigrations 时,它给出了 TypeError: allow_migrate() got an unexpected keyword argument 'model_name'

这是完整的堆栈跟踪:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 353, in execute
self.check()
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/cicd/.local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(**kwargs))
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/base.py", line 1266, in check
errors.extend(cls._check_fields(**kwargs))
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/base.py", line 1337, in _check_fields
errors.extend(field.check(**kwargs))
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 893, in check
errors = super(AutoField, self).check(**kwargs)
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 310, in _check_backend_specific_checks
if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name):
File "/home/cicd/.local/lib/python2.7/site-packages/django/db/utils.py", line 300, in allow_migrate
allow = method(db, app_label, **hints)
TypeError: allow_migrate() got an unexpected keyword argument 'model_name'

如果您能帮助调试此错误并尝试了解导致此错误的原因,我将不胜感激。

最佳答案

当我从 1.6.* 移动到 1.10 时,我遇到了同样的问题。最后我发现了 DATABASE_ROUTERS

引起的问题

老版本我是这样写的

class OnlineRouter(object):
# ...
def allow_migrate(self, db, model):
if db == 'myonline':
return model._meta.app_label == 'online'
elif model._meta.app_label == 'online':
return False
return None

它通过这样重写来工作

class OnlineRouter(object):
# ...
def allow_migrate(self, db, app_label, model_name=None, **hints):
if db == 'my_online':
return app_label == 'online'
elif app_label == 'online':
return False
return None

更多细节见https://docs.djangoproject.com/en/1.10/topics/db/multi-db/#an-example

关于python - Django 类型错误 : allow_migrate() got an unexpected keyword argument 'model_name' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39282860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com