MySQL 错误 1264:列值超出范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14284494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Error 1264: out of range value for column
提问by Cin
As I SET
cust_fax in a table in MySQL like this:
正如我SET
在 MySQL 中的一个表中的 cust_fax 一样:
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
`error 1264` 超出列的值
And I want to know where the error is? My set? Or other?
我想知道错误在哪里?我的套餐?或其他?
Any answer will be appreciated!
任何答案将不胜感激!
回答by Salman A
The value 3172978990 is greater than 2147483647 – the maximum value for INT
– hence the error. MySQL integer types and their ranges are listed here.
值 3172978990 大于 2147483647——最大值INT
——因此错误。MySQL 整数类型及其范围在此处列出。
Also note that the (10)
in INT(10)
does not define the "size" of an integer. It specifies the display widthof the column. This information is advisory only.
还要注意(10)
inINT(10)
没有定义整数的“大小”。它指定列的显示宽度。此信息仅供参考。
To fix the error, change your datatype to VARCHAR
. Phone and Fax numbers should be stored as strings. See this discussion.
要修复错误,请将您的数据类型更改为VARCHAR
. 电话和传真号码应存储为字符串。请参阅此讨论。
回答by Rohit Kolhekar
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. :)
您还可以将数据类型更改为 bigInt,它将解决您的问题,除非需要,否则将整数保留为字符串不是一个好习惯。:)
ALTER TABLE T_PERSON MODIFY mobile_no BIGINT;
回答by Saharsh Shah
You are exceeding the length of intdatatype. You can use UNSIGNEDattribute to support that value.
您超出了int数据类型的长度。您可以使用UNSIGNED属性来支持该值。
SIGNED INTcan support till 2147483647and with UNSIGNED INTallows double than this. After this you still want to save data than use CHARor VARCHARwith length 10
SIGNED INT可以支持到2147483647并且UNSIGNED INT允许比这加倍。在此之后,您仍然希望保存数据而不是使用长度为 10 的CHAR或VARCHAR
回答by totymedli
tl;dr
tl;博士
Make sure your AUTO_INCREMENT
is not out of range. In that case, set a new value for it with:
确保您AUTO_INCREMENT
没有超出范围。在这种情况下,为它设置一个新值:
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.
AUTO_INCREMENT
可以包含一个大于数据类型允许的最大值的数字。如果您填满了一张后来清空的表但AUTO_INCREMENT
保持不变,则可能会发生这种情况,但也可能有不同的原因。在这种情况下,新条目的 id 将超出范围。
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:
如果这是您的问题的原因,您可以通过设置AUTO_INCREMENT
为比最新行的 id 大 1来修复它。因此,如果您的最新行的 id 为 100,则:
ALTER TABLE table_name AUTO_INCREMENT=101
If you would like to check AUTO_INCREMENT
's current value, use this command:
如果您想检查AUTO_INCREMENT
的当前值,请使用以下命令:
SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DatabaseName'
AND TABLE_NAME = 'TableName';
回答by jorge adrian rodriguez
Work with:
与:
ALTER TABLE `table` CHANGE `cust_fax` `cust_fax` VARCHAR(60) NULL DEFAULT NULL;