Error Code: 1406. Data too long for column - MySQL

前端 未结 8 1623
抹茶落季
抹茶落季 2020-11-27 05:26

Error Code: 1406. Data too long for column

CREATE  TABLE `TEST` 
(

  `idTEST` INT NOT NULL ,

  `TESTcol` VARCHAR(45) NULL ,

  PRIMARY KEY (`idTEST`) 
);
         


        
8条回答
  •  悲哀的现实
    2020-11-27 06:09

    I think that switching off the STRICT mode is not a good option because the app can start losing the data entered by users.

    If you receive values for the TESTcol from an app you could add model validation, like in Rails

    validates :TESTcol, length: { maximum: 45 }
    

    If you manipulate with values in SQL script you could truncate the string with the SUBSTRING command

    INSERT INTO TEST
    VALUES
    (
        1,
        SUBSTRING('Vikas Kumar Gupta Kratika Shukla Kritika Shukla', 0, 45)
    );
    

提交回复
热议问题