跨app时外健的坑

跨app时外健的坑

/usr/local/bin/python3.5 /Users/tianzhh/webbubble_web/backend/manage.py runserver 8000
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10b3e6ea0>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check(display_num_errors=True)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 405, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
policies.Site.user: (fields.E300) Field defines a relation with model 'User', which is either not installed, or is abstract.
policies.Site.user: (fields.E307) The field policies.Site.user was declared with a lazy reference to 'policies.user', but app 'policies' doesn't provide model 'user'.
policies.Site_user.user: (fields.E307) The field policies.Site_user.user was declared with a lazy reference to 'policies.user', but app 'policies' doesn't provide model 'user'.

WARNINGS:
policies.Site.node: (fields.W340) null has no effect on ManyToManyField.
policies.Site.user: (fields.W340) null has no effect on ManyToManyField.

System check identified 5 issues (0 silenced).

代码

from apps.users.models import User # users是另一个app,跨app导入

# 该外健字段
 user = models.ManyToManyField(
        to="User",
        related_name="sites",
        db_constraint=False,
        null=True,
        verbose_name=u'用户')

注意:这样会报上边的错

改为:

user = models.ManyToManyField(
        to="users.User",
        related_name="sites",
        db_constraint=False,
        null=True,
        verbose_name=u'用户')

运行ok

其他处理的答案

在setting中加:

你再项目中又创建了apps文件夹时

sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
posted @ 2020-04-13 18:02  tianzhh_lynn  阅读(413)  评论(0编辑  收藏  举报