Cannot add or update a child row: a foreign key constraint fails (`company`.`employee`, CONSTRAINT.

 Cannot add or update a child row: a foreign key constraint fails (`company`.`employee`, CONSTRAINT `employee_department_department_id_fk` FOREIGN KEY (`department_id`) REFERENCES `department` (`department_id`))Cannot add or update a child row: a foreign key constraint fails (`company`.`employee`, CONSTRAINT._第1张图片很明显插入的时候失败了。我寻找了一下原因,原来是插入数据的时候,外键的值在对应表的主键中不存在,所以插入失败。这个问题挺隐蔽的,积累经验啦。

你可能感兴趣的:(数据库,sql)