用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