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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:27:14  来源:igfitidea点击:

Incorrect integer value: '' for column 'id' at row 1

mysqlinsert

提问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 idis an AUTO_INCREMENTinteger 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_INCREMENTfield you have three options:

要让 MySql 为AUTO_INCREMENT字段生成序列号,您有三个选项:

  1. specify list a column list and omit your auto_incremented column from it as njk suggested. That would be the best approach.See comments.
  2. explicitly assign NULL
  3. explicitly assign 0
  1. 按照 njk 的建议,指定 list 列列表并从中省略 auto_incremented 列。那将是最好的方法。看评论。
  2. 显式分配 NULL
  3. 显式赋值 0

3.6.9. Using AUTO_INCREMENT:

3.6.9. 使用 AUTO_INCREMENT

...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 自动分配了序列号。您还可以为列显式分配NULL0以生成序列号。

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 nullwithout 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 = ""