1 번 테이블
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| UserID | int(11) | NO | PRI | NULL | auto_increment |
| Password | varchar(20) | NO | | | |
| Username | varchar(25) | NO | | | |
| Email | varchar(60) | NO | | | |
+----------+-------------+------+-----+---------+----------------+
표 2
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| UserID | int(11) | NO | MUL | | |
| PostID | int(11) | NO | PRI | NULL | auto_increment |
| Title | varchar(50) | NO | | | |
| Summary | varchar(500) | NO | | | |
+------------------+--------------+------+-----+---------+----------------+
오류:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Cannot add or update a child row: a foreign key constraint fails
(`myapp/table2`, CONSTRAINT `table2_ibfk_1` FOREIGN KEY (`UserID`)
REFERENCES `table1` (`UserID`))
내가 뭘 잘못 했니? http://www.w3schools.com/Sql/sql_foreignkey.asp를 읽었으며 무엇이 잘못되었는지 알 수 없습니다.
table2.UserID
존재하지 않는 값을 삽입 / 업데이트하려고합니다 table1.UserID
.