Таблица 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
.