mysql django.db.utils.InterfaceError: (0, '')
DjangoMySQL
2020-11-08 10:53 (6 years ago)

django.db.utils.InterfaceError: "(0, '')"
When this error appears
If this error occurs intermittently when retrieving records or tables, the connection character encoding might not be correct.
If you are connecting with utf8, try switching to utf8mb4 and see if that resolves the issue.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "....",
"USER": "....",
"PASSWORD": "....",
"HOST": "....",
"PORT": "",
"OPTIONS": {
"charset": "utf8mb4"
},
Additional note on 2021-08-07
As mentioned in the above link, when the MySQL client is version 8.0 and the server is version 5.7, the character encoding cannot be specified from the client-side.
Therefore, regarding character encoding, it is best to specify it on the server-side and not specify it from the client-side
(do not specify OPTIONS in the DATABASES).
Related posts
Tips for Solving the 2027 Malformed Packet Error in MySQL
I removed NO_ENGINE_SUBSTITUTION because I got 'Lost connection to MySQL server during query' in Django
When Connecting to a MySQL 5.7 Server Using a MySQL 8.0 Client, Charset Specification Cannot Be Done from the Client
Starting Django on Docker Alpine Results in django.db.utils.OperationalError: (2000, 'Unknown MySQL error')
Please rate this article (No signup or login required)
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.