MYSQL 中的错误 1022 "Can't write duplicate key in table"。奇怪的部分是其他我用同样的方式创建了其他表
Error 1022 "Can't write duplicate key in table" in MYSQL. Strange part is other I have created other tables with the same way
我正在使用 MSQL Workbench 8.0。我有一个模式,我正在使用外键 ProductId 创建一个新的 table。之前使用相同外键创建的其他 tables 工作正常。然而,有了这个 table,我得到了下面提到的这个奇怪的错误:
The operation failed: There was an error while applying the SQL script
to the database. ERROR 1022: Can't write; duplicate key in the table
'Ing_BuildSpec'
我创建的SQL声明:
CREATE TABLE `iqadb`.`Ing_BuildSpec` (
`IngId` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(50) NULL,
`Quantity` INT NULL,
`Weight` INT NULL,
`Tolerance` VARCHAR(45) NULL,
`Equipment` VARCHAR(50) NULL,
`ProductId` INT NULL,
PRIMARY KEY (`IngId`),
INDEX `ProductId_idx` (`ProductId` ASC),
CONSTRAINT `ProductId`
FOREIGN KEY (`ProductId`)
REFERENCES `iqadb`.`Products` (`ProductId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
你能告诉我问题是什么吗?我检查了其他线程并尝试了他们的方法,但没有用,因此我提出了一个新问题。
解决方案:我们不能有多个同名的外键名称。我已经更改了名称并且有效。
" "
我正在使用 MSQL Workbench 8.0。我有一个模式,我正在使用外键 ProductId 创建一个新的 table。之前使用相同外键创建的其他 tables 工作正常。然而,有了这个 table,我得到了下面提到的这个奇怪的错误:
The operation failed: There was an error while applying the SQL script to the database. ERROR 1022: Can't write; duplicate key in the table 'Ing_BuildSpec'
我创建的SQL声明:
CREATE TABLE `iqadb`.`Ing_BuildSpec` (
`IngId` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(50) NULL,
`Quantity` INT NULL,
`Weight` INT NULL,
`Tolerance` VARCHAR(45) NULL,
`Equipment` VARCHAR(50) NULL,
`ProductId` INT NULL,
PRIMARY KEY (`IngId`),
INDEX `ProductId_idx` (`ProductId` ASC),
CONSTRAINT `ProductId`
FOREIGN KEY (`ProductId`)
REFERENCES `iqadb`.`Products` (`ProductId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
你能告诉我问题是什么吗?我检查了其他线程并尝试了他们的方法,但没有用,因此我提出了一个新问题。
解决方案:我们不能有多个同名的外键名称。我已经更改了名称并且有效。
"