我正在尝试将我的django应用程序从1.8.18更新到1.11.1并面临以下问题 TypeError:allow_migrate()缺少1个必需的位置参数:'model'
我在网上搜索过,但没找到解决问题的方法。这是追溯
Traceback (most recent call last):
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(**kwargs))
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/models/base.py", line 1282, in check
errors.extend(cls._check_fields(**kwargs))
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/models/base.py", line 1357, in _check_fields
errors.extend(field.check(**kwargs))
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 909, in check
errors = super(AutoField, self).check(**kwargs)
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 219, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 321, in _check_backend_specific_checks
if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name):
File "/srv/projects/TcellIDM/env/lib/python3.5/site-packages/django/db/utils.py", line 300, in allow_migrate
allow = method(db, app_label, **hints)
TypeError: allow_migrate() missing 1 required positional argument: 'model'
请帮我检测问题位置或建议我应该在哪里解决问题。
答案 0 :(得分:1)
DATABASE_ROUTERS
设置似乎无法接受类列表,而只能接受点类路径的列表。
代替此:
DATABASE_ROUTERS = [MyRouterClass]
执行此操作:
DATABASE_ROUTERS = ['myapp.routers.MyRouterClass']
该特定路由器类位于myapp/routers.py
中。如果像我一样在设置文件中定义路由器,我怀疑您需要将其移出。
答案 1 :(得分:0)
def allow_migrate(self, db, app_label=None, model_name=None, **hints):
"""
Make sure the auth app only appears in the 'auth_db'
database.
"""
if app_label == 'auth':
return db == 'xxxx'
return None
也许你可以添加model_name = None。 我在app_lable上遇到了类似的错误。