升级内容:

  python版本:3.8.4升到3.10.7

  Django版本:2.2.13升到4.2

 

所遇问题:

1、 error in anyjson setup command: use_2to3 is invalid.

pip3 install setuptools==57.5.0  # 降到58以下即可,因为58之后不再有use_2to3

 2、ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' 

 3、ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' 

4、File "lib/python3.10/site-packages/multiselectfield/db/fields.py", line 80, in __init__

self.validators[0] = MaxValueMultiFieldValidator(self.max_length)
IndexError: list assignment index out of range

if len(self.validators) == 0:
    self.validators.append(None)

5、raise InvalidTemplateLibrary(

django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': cannot import name 'parse_header' from 'django.http.multipartparser' 

pip install djangorestframework --upgrade

6、ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ModuleNotFoundError: No module named 'rest_framework_jwt'.

pip install djangorestframework-jwt

7、ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'smart_text' from 'django.utils.encoding' 

pip install djangorestframework-simplejwt
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

8、获取到token,但无法登录,401 Unauthorized

原因djangorestframework-jwt换到djangorestframework-simplejwt,相关代码未及时更改;
 9、python manage.py run server提示system.Roles: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the SystemConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
原因:
从Django 3.2开始,您现在可以在您的设置(settings)中自定义自动创建的主键的类型。
在Django 3.2中开始新项目时,主键的默认类型设置为BigAutoField,这是一个64位整数(64 bit integer)。但是,早期版本将隐式主键的类型设置为整数(integer)。
解决:setting.py中添加:
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'