I'm trying to set unique contraints for multiple columns in the database for my WordPress plugin. I have seen many answers to similar questions here on Stack, but I'm unable to make it work in my context. I followed the WordPress documentation for Creating Tables with Plugins.
I have tried
CREATE TABLE media (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name tinytext NOT NULL,
email VARCHAR(100) NOT NULL,
CONSTRAINT mediaID UNIQUE (id, email)
) $charset_collate;
and
CREATE TABLE media (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name tinytext NOT NULL,
email VARCHAR(100) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;
ALTER TABLE media
ADD UNIQUE (email)
Unfortunately non of these works, as I'm able to add two records with same email address. I have tried to enter "ALTER TABLE..." manually into phpMyAdmin, and then it works. But not in the plugin code.