I have a table:
CREATE TABLE `payments` ( `id` int(9) unsigned zerofill NOT NULL AUTO_INCREMENT, ... `payments_types_id` smallint(3) unsigned NOT NULL DEFAULT '1', ... `service_id` int(9) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `index_service_id` (`service_id`,`payments_types_id`), ) ENGINE=InnoDB AUTO_INCREMENT=900199076 DEFAULT CHARSET=cp1251 The problem concerns the index index_service_id . I want to insert data into the table without filling in the service_id field, and then update the table, making the value of this field equal to the value of the id field, which will ensure the uniqueness of the index index_service_id . At the time of inserting and updating the table, I disable the uniqueness of indexes:
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; LOCK TABLES `payments` WRITE; insert into `payments`(`id`,...) values (100000000, ...), ..., (999999999, ...); //поля service_id в списке параметров нет update `payments` set `service_id` = `id`; UNLOCK TABLES; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; but I still get the error:
Query: insert into
payments(id, ...Error Code: 1062 Duplicate entry '0-0' for key 'index_service_id'
What is the cause of the error? Why does it occur even after disabling index uniqueness checking? Or how to properly disable this check?
UPD
In addition, I would very much like to do this without changing the table schema, if possible.