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