MySQL Error 1264: out of range value for column

后端 未结 5 2148
谎友^
谎友^ 2020-11-29 02:51

As I SET cust_fax in a table in MySQL like this:

cust_fax integer(10) NOT NULL,

and then I insert value like this:

<         


        
5条回答
  •  悲&欢浪女
    2020-11-29 03:05

    tl;dr

    Make sure your AUTO_INCREMENT is not out of range. In that case, set a new value for it with:

    ALTER TABLE table_name AUTO_INCREMENT=100 -- Change 100 to the desired number
    

    Explanation

    AUTO_INCREMENT can contain a number that is bigger than the maximum value allowed by the datatype. This can happen if you filled up a table that you emptied afterward but the AUTO_INCREMENT stayed the same, but there might be different reasons as well. In this case a new entry's id would be out of range.

    Solution

    If this is the cause of your problem, you can fix it by setting AUTO_INCREMENT to one bigger than the latest row's id. So if your latest row's id is 100 then:

    ALTER TABLE table_name AUTO_INCREMENT=101
    

    If you would like to check AUTO_INCREMENT's current value, use this command:

    SELECT `AUTO_INCREMENT`
    FROM  INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = 'DatabaseName'
    AND   TABLE_NAME   = 'TableName';
    

提交回复
热议问题