从django1.x 升级至最新版本 django2.2.5 详细操作记录

先升级 pip install --upgrade django
然后运行 python manage.py check
遇到问题解决问题

E01
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

找到 ~/.virtualenvs/arryblog/lib/python3.6/site-packages/django/db/backends/mysql/base.py
将文件中的如下代码注释
if version < (1, 3, 3):
raise ImproperlyConfigured(“mysqlclient 1.3.3 or newer is required; you have %s” % Database.version)

E02
TypeError: init() missing 1 required positional argument: ‘on_delete’

使用编辑器的正则替换
Find: models.ForeignKey((.+))
Replace: models.ForeignKey($1,on_delete=models.CASCADE)

E03
ModuleNotFoundError: No module named ‘django.core.urlresolvers’

使用编辑器的替换
Find: from django.core.urlresolvers import
Replace: from django.urls import

E04
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

修改
url(r’^admin/’, include(admin.site.urls)),

url(r’^admin/’, admin.site.urls),

E05
'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.

在每个 urls.py 里添加 app_name = ‘’

E06
File “/home/arry/.virtualenvs/arryblog/lib/python3.6/site-packages/django_comments/init.py”, line 2, in
from django.core import urlresolvers

ImportError: cannot import name ‘urlresolvers’

第三方包django-contrib-comments版本太低 运行
pip install --upgrade django-contrib-comments

E07
django.core.cache.backends.base.InvalidCacheBackendError: Could not find backend ‘django_redis.cache.RedisCache’: cannot import name ‘get_cache’

没有找到django-redis
先升级 pip install --upgrade django-redis

E08
?: (admin.E408) ‘django.contrib.auth.middleware.AuthenticationMiddleware’ must be in MIDDLEWARE in order to use the admin application.
?: (admin.E409) ‘django.contrib.messages.middleware.MessageMiddleware’ must be in MIDDLEWARE in order to use the admin application.

修改 setting.py 里的 MIDDLEWARE_CLASSES 为 MIDDLEWARE

W09
WARNINGS:
?: (urls.W005) URL namespace ‘user’ isn’t unique. You may not be able to reverse all URLs in this namespace

同时定义了两个叫做 user 的 url
url(r’^’, include(‘user.urls’,namespace=‘user’)), # 用户模块
url(r’^user/’, include(‘user.urls’,namespace=‘user’)), # 用户模块
删除一个

最后检查
python manage.py check
没有问题
运行

E10
(‘type’, models.ForeignKey(verbose_name=‘照片类型’, to=‘photo.Album’,on_delete=models.CASCADE),
SyntaxError: invalid syntax

查找替换
Find: ),on_delete=models.CASCADE),
Replace: ,on_delete=models.CASCADE)),

E11
File “/home/arry/.virtualenvs/arryblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py”, line 146, in last_executed_query
query = query.decode(errors=‘replace’)
AttributeError: ‘str’ object has no attribute ‘decode’

修改 decode 为 encode
vi /home/arry/.virtualenvs/arryblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py

定位
:146

E12
AttributeError: module ‘django.contrib.auth.middleware’ has no attribute ‘SessionAuthenticationMiddleware’

取消了 SessionAuthenticationMiddleware (怎么进行session认证呢?)
删除 django.contrib.auth.middleware.SessionAuthenticationMiddleware

E13
You have 8 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, sites.
Run ‘python manage.py migrate’ to apply them.

刚才修改过程修改了 migration
使用 python manage.py migrate --fake

python manage.py runserver
服务器运行正常

E14
TypeError at /
‘bool’ object is not callable

原因使用了
if request.user.is_authenticated():
查找替换 user.is_authenticated() 为 user.is_authenticated

从django 1.8 升级至 django2.2 大功告成

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值