Reputation: 17
i´m trying to insert some values in mysql but i get error code 1136, i verified and one of the values is auto-increment so i don't have to enter that one and the rest give a total of 18 which are exactly the total values i'm writting, could somebody help me?
This is the table im using:
FIELD TYPE NULL KEY DEFAULT EXTRA
id_display_detail int(11) NO PRI auto_increment
amount double NO
amount_lc double NO
exchange double NO
company varchar(10) NO
date datetime NO
description varchar(100) NO
document_number varchar(20) NO
document_type varchar(2) NO
posting_key varchar(3) NO
special_gl varchar(1) NO
status int(11) NO
voucher_number varchar(40) NO
year int(11) NO MUL
id_currency int(11) NO MUL
id_employee int(11) NO MUL
credit bit(1) YES
card_type varchar(45) NO
line_item int(11) YES
And this is my code:
INSERT INTO display_detail VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
Am i missing something?
Upvotes: 1
Views: 559
Reputation: 259
It appears that you aren't listing the columns in your INSERT statement. A MySQL query typically looks like this:
INSERT INTO table
(column1, column2, ... )
VALUES
(expression1, expression2, ... ),
(expression1, expression2, ... ),
...;
(Taken from: http://www.techonthenet.com/mysql/insert.php)
The final query would be something like this:
INSERT INTO display_detail
(amount, amount_lc, exchange, company, date, description,
document_number, document_type, posting_key,special_gl,status,voucher_number,year,
id_currency, id_employee, credit, card_type, line_item)
VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
Upvotes: 0
Reputation: 133360
You missing the column name (Because the id is automatic the values you provided don't math the number of column so must declare the column name)
INSERT INTO display_detail ( amount,
amount_lc ,
exchange ,
company ,
date ,
description ,
document_number,
document_type ,
posting_key ,
special_gl ,
status ,
voucher_number ,
year ,
id_currency ,
id_employee ,
credit ,
card_type ,
line_item ) VALUES (300,300,0,'2001','2016-04-11',
'Downpayment ZM00080621','2000010802','ZP','29','R',0,
'GCCTEA 8062130',2016,1,1561,0,NULL,1);
Upvotes: 1
Reputation: 96241
and one of the values is auto-increment so i don't have to enter that one
That doesn't change the fact that the number of values in your VALUES clause has to match the number of columns.
You need to either specify NULL as the value for the auto_increment column - or specify a column list after INSERT first.
Upvotes: 2