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

Study notes to write the first program of Vue

Table of contents 1. Write an HTML, the first Vue...

Jenkins packaging microservices to build Docker images and run them

Table of contents Environment Preparation start 1...

Introduction to encryption of grub boot program in Linux

Table of contents 1. What is grub encryption 2. g...

Sample code for implementing 3D book effect with CSS

Without further ado, let's take a look at the...

SVG+CSS3 to achieve a dynamic wave effect

A vector wave <svg viewBox="0 0 560 20&qu...

How to use LibreOffice to convert document formats under CentOS

Project requirements require some preprocessing o...

Complete example of vue polling request solution

Understanding of polling In fact, the focus of po...

Usage and difference of Js module packaging exports require import

Table of contents 1. Commonjs exports and require...

mysql backup script and keep it for 7 days

Script requirements: Back up the MySQL database e...

Mini Program to Implement Sieve Lottery

This article example shares the specific code of ...

VMware12 installs Ubuntu19.04 desktop version (installation tutorial)

1. Experimental description In the virtual machin...

How to deploy redis in linux environment and install it in docker

Installation Steps 1. Install Redis Download the ...

Creation, constraints and deletion of foreign keys in MySQL

Preface After MySQL version 3.23.44, InnoDB engin...