Error 'Cannot add or update a child row: a foreign key constraint fails
2017-06-11 16:07
567 查看
今天做一个Java Web(MySql数据库) 项目的时候,遇到了Error 'Cannot add or update a child row: a foreign key constraint fails这个错误,上网查了查,有一种的方法是:
插入数据前:SET FOREIGN_KEY_CHECKS=0;
插入数据后:SET FOREIGN_KEY_CHECKS=1;
用此方法试了试,错误依旧存在,然后我就去查看我的Servlet:BeanUtils.setProperty(food, name, value); 我发现我用了BeanUtils工具,这个工具最大的特点就是在jsp页面表单中的 input的name 属性字段要与数据库中每个字段对应起来,这样在封装的时候才不会出错.到jsp页面一找,还真发现存在不一样的字段,所以如果你也有类似的错误的话,不妨查看一下有没有这个错误.(工具随好用,但一定要注意每种工具使用的前提,或者是需要特别注意的地方)
插入数据前:SET FOREIGN_KEY_CHECKS=0;
插入数据后:SET FOREIGN_KEY_CHECKS=1;
用此方法试了试,错误依旧存在,然后我就去查看我的Servlet:BeanUtils.setProperty(food, name, value); 我发现我用了BeanUtils工具,这个工具最大的特点就是在jsp页面表单中的 input的name 属性字段要与数据库中每个字段对应起来,这样在封装的时候才不会出错.到jsp页面一找,还真发现存在不一样的字段,所以如果你也有类似的错误的话,不妨查看一下有没有这个错误.(工具随好用,但一定要注意每种工具使用的前提,或者是需要特别注意的地方)
相关文章推荐
- error:Cannot add or update a child row: a foreign key constraint fails (`xx库`.`xx表`,
- mysql添加外键失败:sql 1452 Cannot add or update a child row:a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- [Mysql] 添加外键失败:Cannot add or update a child row:a foreign key constraint fails
- 1452, 'Cannot add or update a child row: a foreign key constraint fails
- MySql外键添加失败:java.ql.SQLException: Cannot add or update a child row: a foreign key constraint fails
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- django admin报错IntegrityError:'Cannot add or update a child row: a foreign key constraint fails'
- 刷新数据库总是报错:不能增加或者更新约束, Cannot add or update a child row: a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails 无法添加外键
- cannot add or update a child row: a foreign key constraint fails
- mysql添加外键失败:sql 1452 Cannot add or update a child row:a foreign key constraint fails
- Cannot add or update a child row: a foreign key constraint fails (`mysql`.`ordermx`, CONSTRAINT `kf
- Cannot add or update a child row: a foreign key constraint fails 解决办法
- ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
- IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constrai nt fails (`mxonline
- navicat中添加表外键显示Cannoot add or update a child row;a foreign key constraint fails
- ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails