I'm trying to run an INSERT query via a python program for thousands of records which have nullable fields as well. My requirement is such that the result set is transformed into key-value pairs in a dictionary and then parse the values into a list for executing INSERT query. However, when I try to add a NULL value to an int type field and execute INSERT via the program, I hit an error as shown below:
Warning: (1366, "Incorrect integer value: 'NULL' for column 'category_id' at row 1") result = self._query(query)
In the MySQL DB if I execute the query with 'NULL' or 'DEFAULT' keyword for the value of 'category_id', the value gets updated as NULL as expected.
Can someone please help zero in on what I'm missing here? Following is my code snippet:
for s in result:
temp_dict = {}
for key, value in enumerate(s):
if value is None:
temp_dict[key] = pymysql.NULL
else:
temp_dict[key] = str(value)