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 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! You may also be interested in:
|
<<: In-depth understanding of React Native custom routing management
>>: Detailed explanation of the use of Linux seq command
There is a requirement for a list containing mult...
There are caches everywhere inside MySQL. When I ...
1. Add the viewport tag to the HTML header. At th...
1. The Chinese garbled characters appear in MySQL...
I recently discovered a pitfall in regular expres...
Table of contents Vue this.$store.state.xx.xx Get...
1. Install mysql Run the following command to upd...
This article example shares the specific code of ...
Exploiting a newly discovered sudo vulnerability ...
Let our users choose whether to move forward or ba...
When nginx receives a request, it will first matc...
summary In some scenarios, there may be such a re...
What is high concurrency? The default Linux kerne...
This article shares the specific code of JS to ac...
Table of contents Overview 1. RangeError 2. Refer...