一、運(yùn)行項目報錯信息如下:
File "/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in module>
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
mysql版本太低了,進(jìn)入/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-
packages/django/db/backends/mysql/base.py,用vim將其打開
![](/d/20211018/dacb69119723b559cf75d1c60a7b1c85.gif)
35,36行需要注釋掉,然后就不會因為版本而報錯,在末行模式下輸入wq保存退出
![](/d/20211018/5aed38ea5383a128c0e4f0b928d65100.gif)
二、再次運(yùn)行項目報如下錯誤
File "/home/pyvip/.virtualenvs/myblog/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'
使用vim進(jìn)入/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py中
在第146行中,將decode改為encode即可
![](/d/20211018/adaf07eda9bba4481aad386e7ca4db05.gif)
此時再次運(yùn)行項目,可以看到運(yùn)行成功了?。?!證明mysql數(shù)據(jù)庫連接成功!
![](http://img.jbzj.com/file_images/article/201910/2019100810140036.png?201998102459)
總結(jié)
以上所述是小編給大家介紹的django2.2版本連接mysql數(shù)據(jù)庫的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
您可能感興趣的文章:- django連接mysql數(shù)據(jù)庫及建表操作實例詳解
- Django配置MySQL數(shù)據(jù)庫的完整步驟
- 圖文詳解Django使用Pycharm連接MySQL數(shù)據(jù)庫
- Django使用Mysql數(shù)據(jù)庫已經(jīng)存在的數(shù)據(jù)表方法
- Django+mysql配置與簡單操作數(shù)據(jù)庫實例代碼
- Django1.7+python 2.78+pycharm配置mysql數(shù)據(jù)庫教程
- Django框架配置mysql數(shù)據(jù)庫實現(xiàn)過程