刷新数据库总是报错:不能增加或者更新约束, Cannot add or update a child row: a foreign key constraint fails

$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
 Cannot add or update a child row: a foreign key constraint fails (`manager2`.`#sql-7d0_26`, CONSTRAINT `FKgg6g1h63qg29is5ypae70elgt` FOREIGN KEY (`model_id`) REFERENCES `saas_model` (`id`))
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 

这是因为数据冗余造成不能正常更行数据,删去这些数据就行了,认真看报错信息,给的提示也挺完整的,比如:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
 Cannot add or update a child row: a foreign key constraint fails 
(`manager2`.`#sql-7d0_21`, CONSTRAINT `FK47i0hrv2j92ffjagi98vf3si9` FOREIGN KEY (`parent_id`) REFERENCES `saas_element` (`id`))
	at 
就是table saas_element 中id 和parent_id  冲突,具体是,parent_id ,已经删去,但是仍然存在parent为xxx的数据;

select * from saas_element a where a.parent_id not in  (select id from saas_element ) 

-----------------over--------------

下面是我自己的删除数据

select * from saas_element a where a.parent_id not in  (select id from saas_element )  
父id 不在id中;即有父但是父已经不存在的,所有数据
select * from saas_modelfield a where a.model_id not in  (select id from saas_model )  
在 modelfield 表中,查model_id 已经不存在但是还有数据的这些信息

select * from saas_taglibimport a where a.layout_id not in  (select id from saas_layout a where a.model_id not in  (select id from saas_model )  )  
layout_element
select * from saas_layout_element a where a.Layout_id not in  (select id from saas_layout a where a.model_id not in  (select id from saas_model )  )  
delet table ,tagcatagroy,tagimport 

select * from saas_layout a where a.model_id not in  (select id from saas_model )  

select * from saas_taginfoproperty a where a.taginfo_id not in  (select id from saas_taginfo )  
select * from saas_layout a where a.prevVersion_id not in  (select id from saas_Layout )  
//remove taglibimport retrain of layout
select * from saas_layout a where a.model_id not in  (select id from saas_model )
select * from saas_layout a where a.prevVersion_id not in  (select id from saas_Layout )

//menu ,pageid

select * from saas_page a where a.layout_id not in  (select id from saas_layout )  
//删去能删的数据剩下page Id 88;in saas_menu 
select * from saas_page a where a.layout_id not in  (select id from saas_layout )

select * from saas_layout_element a where a.layout_id not in  (select id from saas_layout )

//menu_page page,
select * from saas_menu_page a where a.relevantPages_id not in  (select id from saas_page )
//e
select * from saas_taglibimport a where a.layout_id not in  (select id from saas_layout )  

http://blog.csdn.net/flymoringbird/article/details/52468966
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE //这个是查询出所有的主键和外键


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值