1 背景

在pip install django-haystack时

Django原本是1.11.11, 安装这个包之后会自动升级为3.2版本, 它这个包需要的Django版本必须要高于2.2

报错信息是:

'Specifying a namespace in include() without providing an app_name ’
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in
include() without providing an app_name is not supported. Set the
app_name attribute in the included module, or pass a 2-tuple
containing the list of patterns and app_name instead.

2 解决问题

不难分析, 这个应该是Django由1.X升级到3.X带来的新问题
Django3.X要改为下面这种写法

但现在又出了一堆警告, 大致意思就是现在需要自动创建主键应该要声明
于是我们来到配置文件(默认是settings.py), 在后面添加一句

DEFAULT_AUTO_FIELD = ‘django.db.models.AutoField’


现在就又可以正常使用啦~