user2132046 user2132046 - 1 month ago 9
MySQL Question

1062 Mysql - can't find the reason

I'm getting this error:


#1062 - Duplicate entry '127' for key 'PRIMARY'


and can't find the reason.

The query :

INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('00');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('01');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('02');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('03');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('04');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('05');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('06');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('07');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('08');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('09');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('0F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('10');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('11');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('12');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('13');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('14');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('15');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('16');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('17');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('18');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('19');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('1F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('20');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('21');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('22');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('23');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('24');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('25');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('26');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('27');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('28');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('29');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('2F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('30');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('31');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('32');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('33');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('34');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('35');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('36');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('37');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('38');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('39');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('3F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('40');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('41');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('42');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('43');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('44');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('45');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('46');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('47');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('48');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('49');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('4F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('50');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('51');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('52');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('53');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('54');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('55');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('56');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('57');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('58');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('59');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('5F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('60');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('61');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('62');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('63');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('64');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('65');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('66');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('67');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('68');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('69');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('6F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('70');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('71');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('72');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('73');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('74');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('75');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('76');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('77');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('78');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('79');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('7F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('80');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('81');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('82');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('83');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('84');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('85');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('86');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('87');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('88');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('89');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('8F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('90');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('91');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('92');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('93');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('94');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('95');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('96');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('97');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('98');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('99');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9A');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9B');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9C');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9D');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9E');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('9F');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('A9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AD');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('AF');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('B9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BD');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('BF');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('C9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CD');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('CF');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('D9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DD');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('DF');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('E9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('EA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('EB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('EC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('ED');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('EE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('EF');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F0');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F1');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F2');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F3');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F4');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F5');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F6');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F7');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F8');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('F9');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FA');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FB');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FC');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FD');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FE');
INSERT INTO `portautomadb`.`tag` (`codigo`) VALUES ('FF');


the table's structure :

CREATE TABLE `tag` (  
`idtag` tinyint(4) NOT NULL AUTO_INCREMENT,  
`codigo` varchar(3) NOT NULL,  
PRIMARY KEY (`idtag`),  
UNIQUE KEY `codigo_UNIQUE` (`codigo`)
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8


need help thank you.

Answer Source

signed TINYINT can contain numbers frmo -128 to 127. You most likely already have 127 rows in your table, so your primary key column can't contain more. Change your datatype do SMALLINT UNSIGNED (0-65535) MEDIUMINT UNSIGNED (0-16777215) or just INT UNSIGNED (0-4294967295) - that lasst one should be more than enough