Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

insert

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.

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')"; 
like image 629
AnchovyLegend Avatar asked Feb 07 '13 23:02

AnchovyLegend


People also ask

What is incorrect integer?

Re: Incorrect integer value [Answer] '' means you are setting priority to a string, not an integer. You should use NULL (without quotes) instead, or, to set it to the default 0, leave priority out of the query altogether.

What is error code 1366 MySQL?

To conclude, the ERROR 1366: Incorrect string value happens when MySQL can't insert the value you specified into the table because of incompatible encoding. You need to modify or remove characters that have 4-bytes UTF-8 encoding, or you can change the encoding and collation used by MySQL.


2 Answers

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.

INSERT INTO workorders (column1, column2) VALUES ($column1, $column2) 
like image 182
Kermit Avatar answered Sep 17 '22 15:09

Kermit


To let MySql generate sequence numbers for an AUTO_INCREMENT field you have three options:

  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

3.6.9. Using AUTO_INCREMENT:

...No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign NULL or 0 to the column to generate sequence numbers.

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', ..."; 
like image 25
peterm Avatar answered Sep 17 '22 15:09

peterm