Django2.* + Mysql5.7 development environment integration tutorial diagram

Django2.* + Mysql5.7 development environment integration tutorial diagram

environment:

MAC_OS 10.12

Python 3.6

mysql 5.7.25

Django 2.2.3

Prerequisite: Python, Django and MySQL have been successfully installed and can be run separately

1. Database configuration in settings

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    "USER": "user name",
    "PASSWORD": "your password",
    "NAME": "db name"
  }
}

2. Change the default database driver

1. Install pymysql

pip3 install pymysql

2. Replace the driver

Find the main package of the project. For example, if the project is called TEST, find the __init__.py file under the TEST package.

Add the following code:

import pymysqlpymysql.install_as_MySQLdb()

3. Problem solving:

Question 1: mysqlclient version issue

"""
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
"""

Solution: Follow the path in the figure to find the corresponding lines 35 and 36 and comment them out;

Question 2: String encoding and decoding problem

"""
AttributeError: 'str' object has no attribute 'decode'
"""

Solution: Click on the exception tracking information, find line 146 in operations.py and change decode to encode:

Test run:

PS: The reason for modifying the source code is probably the compatibility issue between Django 2, Python 3 and PyMySQL. In addition, the reason for choosing 2.* is because of the official support time.

The default database driver for Django is mysqlclient, but during testing, it was found that it could not run at all, and the import of various mysql libraries failed! .......

Summarize

The above is the illustrated tutorial of Django2.* + Mysql5.7 development environment integration 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:
  • Summary of Django connection to MySQL configuration method (recommended)
  • Django uses the existing data table method of Mysql database
  • Django reads Mysql data and displays it on the front end
  • Django restarts after reinstalling MySQL and reports an error: How to solve the problem of No module named 'MySQLdb'
  • Django+mysql configuration and simple operation database example code
  • How to install Python3 and Django under Linux and configure MySQL as the default Django server
  • Deploy Apache+Python+Django+MySQL environment on Linux system
  • Django1.7+python 2.78+pycharm configuration mysql database tutorial
  • Python Django connects to MySQL database to add, delete, modify and query

<<:  In-depth understanding of React Native custom routing management

>>:  Detailed explanation of the use of Linux seq command

Recommend

Several popular website navigation directions in the future

<br />This is not only an era of information...

JavaScript to implement mobile signature function

This article shares the specific code of JavaScri...

Vue practice of preventing multiple clicks

Generally, click events will be divided into diff...

CSS horizontal progress bar and vertical progress bar implementation code

Sometimes it’s nice to see some nice scroll bar e...

How to use CSS to display multiple images horizontally in the center

Let me first talk about the implementation steps:...

Some ways to eliminate duplicate rows in MySQL

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

Implementation of nginx worker process loop

After the worker process is started, it will firs...

The difference between this.$router and this.$route in Vue and the push() method

The official document states: By injecting the ro...

Complete example of vue polling request solution

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

Details on how to write react in a vue project

We can create jsx/tsx files directly The project ...

Sharing of experience on repairing MySQL innodb exceptions

A set of MySQL libraries for testing. The previou...

VMware ESXi 5.5 deployment and configuration diagram process

Table of contents 1. Installation requirements 2....