INSERT ON DUPLICATE KEY UPDATE Mysql query is not working with Postmeta table. It adds new/duplicate rows to the table. I couldn't find a way to solve this. I need to use this as part of a bulk import script.
My query is:
INSERT INTO \`wp_postmeta\` (\`post_id\`, \`meta_key\`, \`meta_value\` )
VALUES (21100,"bygg_address","BILGATAN1 9 222B")
ON DUPLICATE KEY UPDATE `meta_value` = "BILGATAN1 92 B";
Even though I have a row with 21100, "bygg_address", "BILGATAN1 9 222B", it inserts a duplicate row instead of updating it.
SHOW CREATE TABLE OUTPUT:
CREATE TABLE `wp_postmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`meta_id`),
KEY `post_id` (`post_id`),
KEY `meta_key` (`meta_key`(191)),
KEY `meta_key_post_id` (`meta_key`(191),`post_id`)
) ENGINE=MyISAM AUTO_INCREMENT=221761 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Any help will be appreciated.