Django – Incorrect integer value: ‘True’ for column ‘is_superuser’ at row 1


I was recently deploying one of my recent Django project (with MySQL database) on our custom managed servers. Everything was tested OK and working fine locally. After I deployed my project on the server, I started getting an error message:

Incorrect integer value: ‘True’ for column ‘is_superuser’ at row 1

This error was generating for all the insert operations through Django models with Boolean fields. As the error message suggests, is_superuser expects an integer value however the value which is being tried to insert is ‘True’.  I tried all my settings and configurations related to Django and MySQL and everything seemed fine. After digging in to more details, I figured out that somehow MySQL is getting wrong values while inserting and that could be due to some configurations in MySQLdb module which is actually used by Django to make connections with MySQL database.

After some more analysis, I was able to find out the actual reason of the issue. The MySQLdb module has a configuration file called which actually handles conversion of the data types during selects and inserts. A sample looks like this:

We can see on line number 128:

This line is responsible for converting all the Boolean values to their corresponding integer values and then the string representation of them. This actually calls another function defined on line number 44 to perform this conversion:

On my server, the MySQLdb configuration was customized and the line 128 was commented and due to which this conversion was not being done. Un-commenting this line could break others code so I had to write a small code in file of my Django project to enable this conversion:

and it worked!




One thought on “Django – Incorrect integer value: ‘True’ for column ‘is_superuser’ at row 1

Leave a Reply

Your email address will not be published. Required fields are marked *