I’m specifying a field, username, as unique for my application. As a part of the install the user is able to specify a table prefix if they choose. But the unique index that is automatically created does not inherit that table prefix.
CREATE TABLE IF NOT EXISTS ".$prefix."users (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(50) UNIQUE NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
The index that is automatically created is just named username. If there is a second installation to the same database there would be a conflict.
Is there a way to have the index created with the prefix or do I need to delete the index after the table is created and recreate it with the prefix?
You can supply an explicit index name like so: