用pip进行更新后
pip install --upgrade Django==2.2
一堆报错
-
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解决方法:
找到 python目录下/site-packages/django/db/backends/mysql/base.py,注释掉下方的两行代码
-
TypeError: init() missing 1 required positional argument: ‘on_delete’
解决方法:
表与表之间关联的时候,必须要写on_delete参数
on_delete参数的各个值的含义:
on_delete=None, # 删除关联表中的数据时,当前表与其关联的field的行为
on_delete=models.CASCADE, # 删除关联数据,与之关联也删除
on_delete=models.DO_NOTHING, # 删除关联数据,什么也不做
on_delete=models.PROTECT, # 删除关联数据,引发错误ProtectedError
# models.ForeignKey('关联表', on_delete=models.SET_NULL, blank=True, null=True)
on_delete=models.SET_NULL, # 删除关联数据,与之关联的值设置为null(前提
FK字段需要设置为可空,一对一同理)
# models.ForeignKey('关联表', on_delete=models.SET_DEFAULT, default='默认值')
on_delete=models.SET_DEFAULT, # 删除关联数据,与之关联的值设置为默认值(前提
FK字段需要设置默认值,一对一同理)
on_delete=models.SET, # 删除关联数据,
a. 与之关联的值设置为指定值,设置:models.SET(值)
b. 与之关联的值设置为可执行对象的返回值,设置:models.SET(可执行对象)
- ImportError: cannot import name ‘RegexURLResolver’ from ‘django.urls’ (D:\Anaconda3\envs\scrapy\lib\site-packages\django\urls_init_.py)
解决方式:把下面注释掉的代码换为第二行的代码
# from django.urls import RegexURLResolver, RegexURLPattern
from django.urls.resolvers import URLResolver, URLPattern
- 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.
解决方法:django.urls中include函数第一个参数传入的是tuple类型,其中一个是参数是app_name,且app_name需赋值,在include中改为下面的代码
include(('rbac.urls','rbac'), namespace='rbac')
- query = query.decode(errors=‘replace’)AttributeError: ‘str’ object has no attribute ‘decode’
解决方法:
把decode改为encode
ko
发现还是飘红
虚惊一场
至此,项目成功更新到2.2
感谢此篇博文的部分解惑:https://blog.csdn.net/Arry_Lee/article/details/100746633