---
slug: "mysql-django-no-engine-substitution"
title: "I removed NO_ENGINE_SUBSTITUTION because I got 'Lost connection to MySQL server during query' in Django"
description: "If a Django MySQL connection still hits 'No DB engine substitution' despite setting `ENGINE` to `django.db.backends.mysql`, here is the root cause and fix."
url: "https://www.ytyng.com/en/blog/mysql-django-no-engine-substitution"
publish_date: "2021-11-14T11:10:12Z"
created: "2021-11-14T11:10:12Z"
updated: "2026-05-11T13:21:24.756Z"
categories: ["Django", "MySQL"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/e95bc00b573d4f2d937cb8e34939e6f1.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# I removed NO_ENGINE_SUBSTITUTION because I got 'Lost connection to MySQL server during query' in Django

<p>When issuing a query to MySQL (5.7) using Django</p>
<pre>(2013, 'Lost connection to MySQL server during query')</pre>
<p><br />the error appeared and the process stopped.</p>
<p><br />First, check the innodb_strict_mode with the active connection</p>
<pre><span>SHOW VARIABLES LIKE </span><span>'%innodb_strict_mode%'</span>;</pre>
<p>It needs to be ON.</p>
<p><a href="https://django-mysql.readthedocs.io/en/latest/checks.html#django-mysql-w002-innodb-strict-mode">https://django-mysql.readthedocs.io/en/latest/checks.html#django-mysql-w002-innodb-strict-mode</a></p>
<p>This was already ON.</p>
<p>Next, check the sql_mode.</p>
<pre><span>SELECT </span><span>@@SESSION.sql_mode</span>;</pre>
<pre><span>STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION</span></pre>
<p>Remove NO_ENGINE_SUBSTITUTION from the MySQL server and restart</p>
<p></p>
<pre>STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER</pre>
<p>This issue no longer appears</p>
