Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of connecting to mysql Database in django2.2 version

Shulou Source: shulou.com Published: 2022-06-01 04:27:58 09月28日 Update

1. The error message of the running project is as follows:

File "/ home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in 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.

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

355036 lines need to be commented out, and then there will be no error due to the version. Type wq in the last line mode to save and exit.

Second, 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

In line 146, change decode to encode

If you run the project again at this time, you can see that it has been run successfully! Prove that the mysql database connection is successful!

Summary

The above is the method of connecting to the mysql database in the django2.2 version introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me, and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Tags: Run version project data database success again help method information provenance pattern comment question website error support input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info MySQL Redmi OPPO Reno