This line in my plugin:
$wpdb->query("ALTER TABLE {$wpdb->prefix}postmeta ADD CONSTRAINT postmeta UNIQUE (post_id,meta_key(100))");
gives me the following error:
[Duplicate entry '539-_wp_attachment_image_alt' for key 'postmeta']
I looked for the entry in my database and saw several entries where post_id
is 539 and meta_key
is _wp_attachment_image_alt
, as well as several others with duplicate post_id
s and image alts.
My question is this: are duplicate _wp_attachment_image_alt
meta keys allowed in WordPress? I am trying to understand whether there was an error on this particular site at some point that duplicated the entries, or if it is a normal behaviour.
I know duplicate meta_keys in general can be inserted into the postmeta
table, and I've also got a feeling I should not add and rely on a post_id+meta_key unique key since duplicate meta_keys are allowed in WordPress, right?