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

前端 未结 8 1530
抹茶落季
抹茶落季 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:03

    Try to check the limits of your SQL database. Maybe you'r exceeding the field limit for this row.

    0 讨论(0)
  • 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)
    );
    
    0 讨论(0)
提交回复
热议问题