文章主要介紹了django2.2版本如何連接MySQL數(shù)據(jù)庫,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下。
一、運(yùn)行項(xiàng)目報(bào)錯(cuò)信息如下:
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.
ysql版本太低了,進(jìn)入/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-
packages/django/db/backends/mysql/base.py,用vim將其打開
35,36行需要注釋掉,然后就不會(huì)因?yàn)榘姹径鴪?bào)錯(cuò),在末行模式下輸入wq保存退出
二、再次運(yùn)行項(xiàng)目報(bào)如下錯(cuò)誤
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即可
此時(shí)再次運(yùn)行項(xiàng)目,可以看到運(yùn)行成功了?。?!證明mysql數(shù)據(jù)庫連接成功!
總結(jié)
以上所述是小編給大家介紹的django2.2版本連接mysql數(shù)據(jù)庫的方法,希望對(duì)大家有所幫助。
- MySQL借助DB實(shí)現(xiàn)分布式鎖思路示例代碼詳解
- MySQL多版本并發(fā)控制MVCC的實(shí)現(xiàn)示例代碼介紹
- mysql group_concat 實(shí)現(xiàn)把分組字段寫成一行的方法
- mysql數(shù)據(jù)庫實(shí)現(xiàn)多表關(guān)聯(lián)統(tǒng)計(jì)、子查詢統(tǒng)計(jì)示例
- MySQL InnoDB數(shù)據(jù)庫如何保證事務(wù)特性示例詳解
- 數(shù)據(jù)庫 MySQL8.0+常用命令及操作命令詳解
- Mysql8.0.17數(shù)據(jù)庫安裝圖文教程
- SQL Server 2000/2005/2008刪除或壓縮數(shù)據(jù)庫日志的方
- SQL Server數(shù)據(jù)庫查看login所授予的具體權(quán)限問題
- SQL Server數(shù)據(jù)庫怎么找出一個(gè)表包含的頁信息(Page)
分享到:
投訴收藏