I used MySQL Workbench to prepare the database layout and exported it to my database using phpMyAdmin. When looking at one table, I received the following warning:
PRIMARY and INDEX keys should not be set for gid column
gid is an external index that is the primary key of another table and which is also part of the primary key of the current table. So I have this as part of the primary key, and Workbench created an index to enter the foreign key. So, why does this warning appear, should I ignore it or review my database layout?
This is a very simplified example of the structure used, which generates a warning:
CREATE TABLE IF NOT EXISTS `test_groups` ( `gid` INT NOT NULL , `gname` VARCHAR(45) NULL , PRIMARY KEY (`gid`) ); CREATE TABLE IF NOT EXISTS `test_users` ( `gid` INT NOT NULL , `uid` INT NOT NULL , `name` VARCHAR(45) NULL , PRIMARY KEY (`gid`, `uid`) , INDEX `gid` (`gid` ASC) , CONSTRAINT `gid` FOREIGN KEY (`gid` ) REFERENCES `test_groups` (`gid` ) ON DELETE CASCADE ON UPDATE CASCADE);
edit I tried removing the extra index for gid in phpMyAdmin and it seems to work. Cascading action still occurs when something changes in the group table, so I think that the external relation is not damaged even without an index.
But why does MySQL Workbench force me to maintain this index? I cannot manually delete it there while there is a foreign key.
source share