
ALTER TABLE `documents_tags` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`); 

ALTER TABLE `documents_files` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`); 

DELETE dt1
FROM documents_tags dt1
JOIN documents_tags dt2
  ON dt1.id_tags = dt2.id_tags
 AND dt1.id_documents = dt2.id_documents
 AND dt1.id > dt2.id;