“ERROR 1406: 1406: Data too long for column” but it shouldn't be?

后端 未结 3 1839
暖寄归人
暖寄归人 2021-02-05 23:54

I have the following table structure:

DROP TABLE IF EXISTS `tblusers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_         


        
3条回答
  •  青春惊慌失措
    2021-02-06 00:05

    IsAdmin has the datatype of bit(1), yet you are assigning the string '1' to it. Indicate that you are assigning a bit value to it by preceeding the '1' with b or use 0b format:

    UPDATE `tblusers` SET `IsAdmin`=b'1'  WHERE `UserID`='79';
    

    or

    UPDATE `tblusers` SET `IsAdmin`=0b1  WHERE `UserID`='79';
    

    The reason for this behaviour is probably that strict_all_tables or strict_trans_tables setting is enabled on the v5.7 mysql server:

    Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE.

提交回复
热议问题