MySQL 不正确的整数值:'' 表示第 1 行的 'id' 列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14762904/
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
Incorrect integer value: '' for column 'id' at row 1
提问by AnchovyLegend
I am trying to insert into my mySQL database. The first column is the 'id' column, since its an auto_increment field, I left it blank. For some reason, I am unable to insert and I am getting the error mentioned below. I appreciate any help with this.
我正在尝试插入到我的 mySQL 数据库中。第一列是“id”列,因为它是一个 auto_increment 字段,我将其留空。出于某种原因,我无法插入,并且出现下面提到的错误。我很感激这方面的任何帮助。
I am getting the following error while trying to insert:
尝试插入时出现以下错误:
Incorrect integer value: '' for column 'id' at row 1
my query
我的查询
$insertQuery = "INSERT INTO workorders VALUES('', '$priority', '$requestType', '$purchaseOrder', '$nte', '$jobSiteNumber')";
回答by Kermit
That probably means that your id
is an AUTO_INCREMENT
integer and you're trying to send a string. You should specify a column list and omit it from your INSERT
.
这可能意味着您id
是一个AUTO_INCREMENT
整数并且您正在尝试发送一个字符串。您应该指定一个列列表并从您的INSERT
.
INSERT INTO workorders (column1, column2) VALUES ($column1, $column2)
回答by peterm
To let MySql generate sequence numbers for an AUTO_INCREMENT
field you have three options:
要让 MySql 为AUTO_INCREMENT
字段生成序列号,您有三个选项:
- specify list a column list and omit your auto_incremented column from it as njk suggested. That would be the best approach.See comments.
- explicitly assign NULL
- explicitly assign 0
- 按照 njk 的建议,指定 list 列列表并从中省略 auto_incremented 列。那将是最好的方法。看评论。
- 显式分配 NULL
- 显式赋值 0
...No valuewas specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign NULLor 0to the column to generate sequence numbers.
...没有为 AUTO_INCREMENT 列指定值,因此 MySQL 自动分配了序列号。您还可以为列显式分配NULL或0以生成序列号。
These three statements will produce the same result:
这三个语句将产生相同的结果:
$insertQuery = "INSERT INTO workorders (`priority`, `request_type`) VALUES('$priority', '$requestType', ...)";
$insertQuery = "INSERT INTO workorders VALUES(NULL, '$priority', ...)";
$insertQuery = "INSERT INTO workorders VALUES(0, '$priority', ...";
回答by PJunior
Try to edit your my.cfand comment the original sql_mode and add sql_mode = "".
尝试编辑您的my.cf并注释原始 sql_mode 并添加sql_mode = ""。
vi /etc/mysql/my.cnf
sql_mode = ""
sql_mode = ""
save and quit...
保存并退出...
service mysql restart
回答by Susampath
This is because your data sending column type is integer and your are sending a string value to it.
这是因为您的数据发送列类型是整数,并且您正在向其发送字符串值。
So, the following way worked for me. Try with this one.
所以,以下方式对我有用。试试这个。
$insertQuery = "INSERT INTO workorders VALUES (
null,
'$priority',
'$requestType',
'$purchaseOrder',
'$nte',
'$jobSiteNumber'
)";
Don't use 'null'
. use it as null
without single quotes.
不要使用'null'
. 使用它作为null
没有单引号。
回答by Machindra
For the same error in wamp/phpmyadmin
, I have edited my.ini
, commented the original :
对于同样的错误wamp/phpmyadmin
,我已经编辑my.ini
、评论了原文:
;sql-mode= "STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
and added sql_mode = ""
.
并补充说sql_mode = ""
。