关于create table命令上的重复键,我收到1022错误。看完查询后,我不知道在哪里进行复制。有人可以看到吗?
SQL query: -- ----------------------------------------------------- -- Table `apptwo`.`usercircle` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `apptwo`.`usercircle` ( `idUserCircle` MEDIUMINT NOT NULL , `userId` MEDIUMINT NULL , `circleId` MEDIUMINT NULL , `authUser` BINARY NULL , `authOwner` BINARY NULL , `startDate` DATETIME NULL , `endDate` DATETIME NULL , PRIMARY KEY ( `idUserCircle` ) , INDEX `iduser_idx` ( `userId` ASC ) , INDEX `idcategory_idx` ( `circleId` ASC ) , CONSTRAINT `iduser` FOREIGN KEY ( `userId` ) REFERENCES `apptwo`.`user` ( `idUser` ) ON DELETE NO ACTION ON UPDATE NO ACTION , CONSTRAINT `idcategory` FOREIGN KEY ( `circleId` ) REFERENCES `apptwo`.`circle` ( `idCircle` ) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE = INNODB; MySQL said: Documentation #1022 - Can't write; duplicate key in table 'usercircle'
您很可能已经在名称iduser或idcategory数据库中具有约束。如果是这样,只需重命名约束即可。
iduser
idcategory
约束对于整个数据库必须是唯一的,而不仅仅是对要创建/更改的特定表。
要找出约束当前在哪里使用,可以使用以下查询:
SELECT `TABLE_SCHEMA`, `TABLE_NAME` FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `CONSTRAINT_NAME` IN ('iduser', 'idcategory');