MySQL Workbench。错误 1452:无法添加或更新子行:外键约束失败。手术失败
MySQL Workbench. ERROR 1452: Cannot add or update a child row: a foreign key constraint fails. Operation failed
我无法通过外键绑定下属(Table管理员)和主要table(部门)。
它显示以下消息:
正在执行:
ALTER TABLE `grocery_supermarket_manager`.`administrator`
ADD CONSTRAINT `AdministratorDepartment_FK`
FOREIGN KEY (`id_department`)
REFERENCES `grocery_supermarket_manager`.`department` (`id_department`)
ON DELETE CASCADE
ON UPDATE CASCADE;
操作失败:将 SQL 脚本应用到数据库时出错。
ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (`grocery_supermarket_manager`.`#sql-9ac_8`, CONSTRAINT `AdministratorDepartment_FK` FOREIGN KEY (`id_department`) REFERENCES `department` (`id_department`) ON DELETE CASCADE ON UPDATE CASCADE)
SQL Statement:
ALTER TABLE `grocery_supermarket_manager`.`administrator`
ADD CONSTRAINT `AdministratorDepartment_FK`
FOREIGN KEY (`id_department`)
REFERENCES `grocery_supermarket_manager`.`department` (`id_department`)
ON DELETE CASCADE
ON UPDATE CASCADE
栏目名称:"id_department"table"Department"有:
- 数据类型 - INT(10)
- 存储:主键、非空、唯一、无符号、自动递增。
栏目名称:"id_department"table"Administrator"有:
- 数据类型 - INT(10)
- 存储:非空,未签名。
确保 table 中的当前数据满足您添加的限制条件。看起来您的管理员的部门 ID 无效。
我无法通过外键绑定下属(Table管理员)和主要table(部门)。 它显示以下消息:
正在执行:
ALTER TABLE `grocery_supermarket_manager`.`administrator`
ADD CONSTRAINT `AdministratorDepartment_FK`
FOREIGN KEY (`id_department`)
REFERENCES `grocery_supermarket_manager`.`department` (`id_department`)
ON DELETE CASCADE
ON UPDATE CASCADE;
操作失败:将 SQL 脚本应用到数据库时出错。
ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (`grocery_supermarket_manager`.`#sql-9ac_8`, CONSTRAINT `AdministratorDepartment_FK` FOREIGN KEY (`id_department`) REFERENCES `department` (`id_department`) ON DELETE CASCADE ON UPDATE CASCADE)
SQL Statement:
ALTER TABLE `grocery_supermarket_manager`.`administrator`
ADD CONSTRAINT `AdministratorDepartment_FK`
FOREIGN KEY (`id_department`)
REFERENCES `grocery_supermarket_manager`.`department` (`id_department`)
ON DELETE CASCADE
ON UPDATE CASCADE
栏目名称:"id_department"table"Department"有:
- 数据类型 - INT(10)
- 存储:主键、非空、唯一、无符号、自动递增。
栏目名称:"id_department"table"Administrator"有:
- 数据类型 - INT(10)
- 存储:非空,未签名。
确保 table 中的当前数据满足您添加的限制条件。看起来您的管理员的部门 ID 无效。