MySQL Error 1264: out of range value for column

409,030

Solution 1

The value 3172978990 is greater than 2147483647 – the maximum value for INT – hence the error. MySQL integer types and their ranges are listed here.

Also note that the (10) in INT(10) does not define the "size" of an integer. It specifies the display width of the column. This information is advisory only.

To fix the error, change your datatype to VARCHAR. Phone and Fax numbers should be stored as strings. See this discussion.

Solution 2

You can also change the data type to bigInt and it will solve your problem, it's not a good practice to keep integers as strings unless needed. :)

ALTER TABLE T_PERSON MODIFY mobile_no BIGINT;

Solution 3

You are exceeding the length of int datatype. You can use UNSIGNED attribute to support that value.

SIGNED INT can support till 2147483647 and with UNSIGNED INT allows double than this. After this you still want to save data than use CHAR or VARCHAR with length 10

Solution 4

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';

Solution 5

Work with:

ALTER TABLE `table` CHANGE `cust_fax` `cust_fax` VARCHAR(60) NULL DEFAULT NULL; 

Share:
409,030
Cin
Author by

Cin

Updated on July 08, 2022

Comments

  • Cin
    Cin almost 2 years

    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:

    INSERT INTO database values ('3172978990');
    

    but then it say

    `error 1264` out of value for column

    And I want to know where the error is? My set? Or other?

    Any answer will be appreciated!

  • Curt
    Curt over 6 years
    If the application is storing a phone number, then using strings is certainly preferred. However, thank you for the ALTER statement. It fixed my problem (plain integer overflow where I was storing file sizes using INTEGER).
  • totymedli
    totymedli about 5 years
    For me, the error was caused by AUTO_INCREMENT somewhy becoming a huge number in a table with a small row count. So I needed ALTER TABLE table_name AUTO_INCREMENT=103; (if there are 102 rows at the moment).
  • Salman A
    Salman A about 5 years
    @totymedli this could make a useful answer for someone experiencing same symptoms but different problem.
  • Winnipass
    Winnipass almost 5 years
    This worked for me ALTER TABLE tbl_name MODIFY tbl_column BIGINT(50) UNSIGNED NOT NULL
  • Whir
    Whir almost 5 years
    Upvoted! Other suggestions to convert to strings are nonsense. Integers are integers for a reason.
  • Reed
    Reed almost 4 years
    I use int for phone numbers, because I sanitize user input by removing all non-numbers.
  • Tipul07
    Tipul07 almost 4 years
    @Reed, I wouldn't recommend using int for phone numbers. If someone would input an international format as 0044.... you will loose 00. Sanitize phone number in your code before sending it to the query.
  • Reed
    Reed almost 4 years
    @Tipul07 You're totally right. VARCHAR it is, then. I dev in the u.s. & most stuff I make is local to my hometown, BUT i still should code with accessibility in mind from day one.
  • Reed
    Reed almost 4 years
    "@Reed I wouldn't recommend using int for phone numbers. If someone would input an international format as 0044.... you will loose 00." - Another comment on this page. I'm going with VARCHAR
  • arun
    arun about 3 years
    cant understand the reason but this one worked for me