How to allow empty string for integer in MySQL?

前端 未结 3 2106
故里飘歌
故里飘歌 2020-12-14 07:48

I have integer fields in a table. The POSTs are send by a complicated JavaScript. They send empty string like \"\" but as you guess MySQL doesn\'t allow emty strings in inte

3条回答
  •  旧巷少年郎
    2020-12-14 08:17

    Assuming that the column allows for NULL values, you must explicitly tell MySQL to use a value of NULL, rather than passing an empty string (which is cast to 0):

    INSERT INTO table (column_name) VALUES (NULL);
    

提交回复
热议问题