异常现象
集成spring 4.3.30.RELEASE 和 hibernate 4.3.10.Final 生成外键时报错
ERROR: Cannot add or update a child row: a foreign key constraint fails
可能的原因
-
数据表存储引擎不一致
-
数据表外键对应的字段数据类型不一致
-
外键对应字段必须设置非空并且唯一
-
两表外键字段值不匹配
例如在table1创建外键
CONSTRAINT `FK_43ffx7lq8po4v0imgxqriig7w` FOREIGN KEY (`foregin_id`) REFERENCES `table2` (`id`)
如果 table1的 foregin_id 字段包含了不在 table2的id字段存在的值,则会创建失败
遇到的其他问题
spring4+hibernate4报错:not allowed in read-only mode;Could not obtain transaction-synchronized Session
spring4+hibernate4报错:Another unnamed CacheManager already exists in the same VM
完结撒花✿✿ヽ(°▽°)ノ✿