Pages

Saturday, February 20, 2016

Incorrect integer value: '' for column - MySQL Server

The MySQL versions were different, previously MySQL 4 working fine code may get error in MySQL 5 because of security enhancement or just a change in the default level of data-validation, but in MySQL 4, if you set an int_column = '', (that's 2 single quotes) it would be converted to the zero value. In MySQL 5, by default, it causes this error "Incorrect integer value".

This is an sql-mode issue, the mode defines what SQL syntax should be supported and what kind of data validation should be performed. To overcome this,  reduce the sensitivity of the control. To lower the level of data validation we can set the sql-mode to a lower level or comment it out altogether.

Edit the my.cnf (my.ini in windows) file and find and comment out the line:

#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

The STRICT_TRANS_TABLES or it might be STRICT_ALL_TABLES is the bit that is causing the problem. STRICT mode is disallows invalid or missing values in a statement and aborts the command.

Save my.ini, restart MySQL.

No comments:

Post a Comment