关于DjangoRuntimeError: Model class doesn't declare an explicit app_label

运行环境

PyCharm 2017.1
Django 2.0.1
python 3.6.1

使用相对路径引用Models模块

from .models import *

在同时存在多个apps的情况下,有机会报错

RuntimeError: Model class app_anme.models.Ad doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

解决办法

使用绝对路径引用

from app_name.models import *

猜你喜欢

转载自blog.csdn.net/weixin_40841752/article/details/79414681