表#1:
表#2:
错误:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (
myapp/table2
, CONSTRAINTtable2_ibfk_1
FOREIGN KEY (UserID
) REFERENCEStable1
(UserID
))
我做错了什么?我读了http://www.w3schools.com/Sql/sql_foreignkey.asp我看不出有什么问题。
最佳答案
您收到此错误是因为您尝试向 table2
添加/更新一行,但根据当前存储在 table1
中的值。如果您发布更多代码,我可以帮助您诊断具体原因。
关于mysql - 无法添加或更新子行 : a foreign key constraint fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40066265/