Python python django 创建第二个 app,配置第二个数据库,一直报错

一本正经 · 2018年12月30日 · 最后由 andward_xu 回复于 2019年01月01日 · 2244 次阅读

Unhandled exception in thread started by
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(
kwargs)
File "/usr/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
errors.extend(model.check(
kwargs))
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 1283, in check
errors.extend(cls._check_fields(
kwargs))
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 1358, in _check_fields
errors.extend(field.check(
kwargs))
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/init.py", line 913, in check
errors = super(AutoField, self).check(
kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/init.py", line 219, in check
errors.extend(self._check_backend_specific_checks(
*kwargs))
File "/usr/local/lib/python2.7/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 "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 293, in allow_migrate
for router in self.routers:
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get
_
res = instance.dict[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 251, in routers
router = import_string(r)()
File "/usr/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named db_router

db_router 文件是我新建的分配数据库的,我在 settings 里也引入了这个文件
配置是按照这样来的
https://blog.csdn.net/weixin_42282496/article/details/80795261
我 python2.7
求大神指点

共收到 1 条回复 时间 点赞

error 提示就是 module 路径不对,查下 router 的 path 在 setting 里面是否正确

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册