What is this error? "Database query failed: Data truncated for column 'column_name' at row 1

前端 未结 3 965
别跟我提以往
别跟我提以往 2021-02-05 04:12

I\'m building a PHP/MySQL application and I\'m running into a problem with my create and update query. I have 5 columns that are set to type FLOAT that are also set as NULL colu

3条回答
  •  眼角桃花
    2021-02-05 04:23

    This isn't meant as a solution, but only to perhaps shed some more light on the problem.

    If you add the keyword IGNORE to the statement, and try to insert '' (or any string not beginning with a number) into a float column, MySQL will insert the value 0, instead of the default value.

    INSERT IGNORE INTO a_table (float_column) VALUE ('')
    
    INSERT IGNORE INTO a_table (float_column) VALUE ('abc')
    

    Both will insert 0, even if the default is null. Without IGNORE, of course, both statements will raise the error you're seeing.

    In short, you get the message because the data you're supplying is neither the expected type nor the default value.

提交回复
热议问题