I have a simple tag_map table as

CREATE TABLE tag_map
(
tag_map_id mediumint(7) unsigned NOT NULL AUTO_INCREMENT,
post_id mediumint(7) unsigned REFERENCES posts(post_id),
tag_id mediumint(7) unsigned REFERENCES tags(tag_id),
UNIQUE INDEX (post_id,tag_id),
PRIMARY KEY(tag_map_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci

I added UNIQUE INDEX to avoid duplicate pairs of a tag associated to a post. Now when I try to add new enteries as

INSERT IGNORE INTO (post_id,tag_id) VALUES (post1_id,tag1_id), (post1_id, tag2_id),...

I will receive an error

ERROR 1062 (23000): Duplicate entry '16777215' for key 'PRIMARY'

but when I SELECT WHERE tag_map_id='16777215'; this belongs to a different tag and post.

Where did I wrong?

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top