I have a string containing more than 600 characters, where I want to Insert it in a column VARCHAR (255) column
I tested on two different databases:
- For a
mysql 5.7.31-34-logdatabase, I ran into this exception:
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1"
- I dumped the sql_mode for each database and this the result:
["@@sql_mode"]=> string(40) "STRICT_ALL_TABLES,NO_ENGINE_SUBSTITUTION"
- On the other hand for a
mysql 5.7.19database, the string is well registered into my database, but with a warning message: Level Code Message
Warning 1265 Data truncated for column 'name' at row 1
- sql_mode:
["@@sql_mode"]=> string(0) ""
I would be grateful if someone could explain to me it is a good practice to disable strict mode, and does truncate remove a part of the string if exceeded ?
STRICT_ALL_TABLEScauses data truncate to be an error whereas with this mode disabled the truncation generates warning only. - Akina