1

I have a room_tb table and seller table. I want create a fk.

ALTER TABLE seller
ADD CONSTRAINT fk_romid
FOREIGN KEY (roomID)
REFERENCES room_tb(roomID)

roomID is primary key in my room_tb table and is autoincrement. roomID is simple integer with same characters as roomID in room_tb but is not autoincrement.

I am getting error:

1452 - Cannot add or update a child row: a foreign key constraint fails (iwant2.<result 2 when explaining filename '#sql-13ec_2c7'>, CONSTRAINT fk_romid FOREIGN KEY (roomID) REFERENCES room_tb (roomID))

What have I done wrong?

4

1 回答 1

0

检查数据库是否有任何数据。有时可用数据也会产生问题。所以最好删除这些数据。

于 2013-08-23T02:47:45.413 回答