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

HTML table tag tutorial (24): horizontal alignment attribute of the row ALIGN

In the horizontal direction, you can set the row ...

CentOS6.8 Chinese/English environment switching tutorial diagram

1. Introduction People who are not used to Englis...

Summary of knowledge points on using calculated properties in Vue

Computed properties Sometimes we put too much log...

Some ways to eliminate duplicate rows in MySQL

SQL statement /* Some methods of eliminating dupl...

Detailed explanation of redo log and undo log in MySQL

The most important logs in the MySQL log system a...

Nginx signal control

Introduction to Nginx Nginx is a high-performance...

Vue realizes picture switching effect

This article example shares the specific code of ...

js canvas to realize the Gobang game

This article shares the specific code of the canv...

CentOS7 firewall and port related commands introduction

Table of contents 1. Check the current status of ...

MySQL sql_mode analysis and setting explanation

When inserting a set of data into the MySQL datab...

MySQL time types and modes details

Table of contents 1. MySQL time type 2. Check the...

How to write asynchronous tasks in modern JavaScript

Preface In this article, we'll explore the ev...

Detailed graphic and text instructions for installing MySQL 5.7.20 on Mac OS

Installing MySQL 5.7 from TAR.GZ on Mac OS X Comp...