1. 程式人生 > >如何解決 mysql Data truncated for column 的錯誤

如何解決 mysql Data truncated for column 的錯誤

How-To-Fix
You have many solutions to fix this awful error:
  1. Add the IGNORE parameter to your INSERT or UPDATE queries to consider this error just a warning.
    Code:
    /* change this */
    INSERT INTO smth ...therestofthequery...;/* to */
    INSERT IGNORE INTO smth ...therestofthequery...;
  2. You should replace the empty string fields '' as NULL for the relative enum/set ones.
    It could be boring, and db could not read such NULL fields at all causing a crash.
    NB: You should also set the field NULLable
    .
  3. Remove the STRICT_TRANS_TABLES flag from the sql_mode variable putting this at the beginning of the query:
    Code:
    SET sql_mode=(SELECT REPLACE(@@sql_mode,'STRICT_TRANS_TABLES',''));
    Or just:
    Code:
    SET sql_mode =''