django中版本不一样发生的错误
错误:ModuleNotFoundError: No module named 'django.core.urlresolvers'
原代码:from django.core.urlresolvers import NoReverseMatch
更改:from django.urls import NoReverseMatch
错误:ModuleNotFoundError: No module named 'django.core.urlresolvers'
原代码:from django.core.urlresolvers import reverse
更改:from django.urls import reverse
错误:ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
原代码:from django.utils.encoding import python_2_unicode_compatible
更改:from six import python_2_unicode_compatible
ps:six需要安装(pip install six)
错误:ImportError: cannot import name 'six' from 'django.utils'
原代码:from django.utils import six
改为:import six
ps:six需要安装(pip install six)
错误:TypeError: __init__() missing 1 required positional argument: 'on_delete'
错误原因:django3版本后外键都需要加on_delete
新增字段:on_delete=models.DO_NOTHING(删除关联数据,不做任何事)
其他值:
None # 删除关联表中的数据时,当前表与其关联的field的行为
momdels.CASSADE # 删除关联数据,与之相关也删除
models.DO_NOTHING # 删除关联数据,不做任何事
models.SET_NULL # 删除关联数据,与之相关值设置为null(需要设置blank,null为True)
models.set_DEFAULT # 删除相关数据,与之相关值设置为默认(需要设置默认值)
models.SET # 删除关联数据