Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or updat
完整错误:
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (ssh_crm
.#sql-138c_a
, CONSTRAINT FKo6oqtbbjmu6890to85xbpymcd
FOREIGN KEY (custLevel
) REFERENCES t_dict
(did
))
翻译:
引起的:com.mysql.jdbc.exceptions。MySQLIntegrityConstraintViolationException:无法添加或更新子行:外键约束失败(’ ssh_crm ‘)。’ #sql-138c_a ‘,约束’ FKo6oqtbbjmu6890to85xbpymcd ‘外键(’ custLevel ‘)引用’ t_dict ’ (’ did '))
问题和解决:
原因是之前创建的custLevel`列已经存在数据库里面了,现在又要作为外键把custlevel和表t_dict(did)进行外键关联,不可以!!必须先注释掉之前类里面的custlevel属性和方法
方法同理注释,然后再到数据库里面把原来创建的custlevel列删除掉,不然不能创建更不能关联外键,
删完了重启Tomcat就能重新创建新的外键。
//欢迎大家提意见了,和交流,谢谢观看