I used MySQL Workbench to prepare a database layout and exported it to my database using phpMyAdmin. When looking at one table, I got the following warning:
PRIMARY and INDEX keys should not both be set for column
gid
gid
is a foreign index which is the primary key of a different table, and which is also part of the primary key of the current table. So I have it as part of the primary key, and Workbench created an index for the foreign key entry. So why is that warning appearing, should I ignore it, or should I rethink my database layout?
This is a very simplified example of the used structure, which produces the 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 deleting the additional index for gid
in phpMyAdmin and it seems to work. The cascade action still happens when changing something in the groups table, so I guess the foreign-relation is intact even without the index.
But why does MySQL Workbench force me to keep that index? I cannot manually remove it there as long as the foreign key is there.