How to connect Django 2.2 to MySQL database

How to connect Django 2.2 to MySQL database

1. The error information reported when running the project is as follows:

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.

The mysql version is too low, enter /home/pyvip/.virtualenvs/myblog/lib/python3.6/site-

packages/django/db/backends/mysql/base.py, open it with vim


insert image description here

Lines 35 and 36 need to be commented out, so that no errors will be reported due to the version. Enter wq in the last line mode to save and exit


insert image description here

2. Run the project again and report the following error

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'

Use vim to enter /home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py and change decode to encode in line 146.


insert image description here

Run the project again at this time, and you can see that it runs successfully! ! ! Prove that the mysql database connection is successful!


Summarize

The above is the method of connecting Django 2.2 version to MySQL database introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed explanation of Django connecting to MySQL database and creating table operations
  • Complete steps for configuring MySQL database in Django
  • Detailed explanation of how to use Pycharm to connect to MySQL database in Django
  • Django uses the existing data table method of Mysql database
  • Django+mysql configuration and simple operation database example code
  • Django1.7+python 2.78+pycharm configuration mysql database tutorial
  • Django framework configuration mysql database implementation process

<<:  Using Vue to implement timer function

>>:  Use of Docker image storage overlayfs

Recommend

How to build YUM in Centos7 environment

1. Enter the configuration file of the yum source...

Analysis of the difference between absolute path and relative path in HTML

As shown in the figure: There are many files conne...

Detailed process of using nginx to build a webdav file server in Ubuntu

Install nginx Note that you must install nginx-fu...

CSS Paint API: A CSS-like Drawing Board

1. Use Canvas images as CSS background images The...

How to write beautiful HTML code

What Beautiful HTML Code Looks Like How to write ...

RHEL7.5 mysql 8.0.11 installation tutorial

This article records the installation tutorial of...

How to modify the default storage engine in MySQL

mysql storage engine: The MySQL server adopts a m...

Summary of ways to implement single sign-on in Vue

The project has been suspended recently, and the ...

Native js to achieve seamless carousel effect

Native js realizes the carousel effect (seamless ...

Vue codemirror realizes the effect of online code compiler

Preface If we want to achieve the effect of onlin...

Simply understand the writing and execution order of MySQL statements

There is a big difference between the writing ord...

Gradient slide effect implemented by CSS3

Achieve results Code html <div class="css...