为什么这会在XAMPP上引发错误:CANT ADD FOREIGN KEY

时间:2015-04-10 14:09:27

标签: mysql sql

为什么会抛出错误“XAMPP:CANT ADD FOREIGN KEY”。

创建表是:

CREATE TABLE FIR_T (
FIR_id INT(5) NOT NULL,
Incident_date DATE NOT NULL,
Incident_place VARCHAR(30),
Time_lodged TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Incident_time TIMESTAMP,
Date_lodged DATE NOT NULL,
Petitioner_id VARCHAR(15),
Victim_Name VARCHAR(50), 
Victim_Address VARCHAR(100),
Case_id INT(10),
Petitioner_Name VARCHAR(50),
CONSTRAINT FIR_PK PRIMARY KEY(FIR_id),
CONSTRAINT FIR_FK1 FOREIGN KEY(victim_name,victim_address) 
REFERENCES Victim_T(name,address),
CONSTRAINT FIR_FK2 FOREIGN KEY(Petitioner_id,Petitioner_Name)
REFERENCES Petitioner_T(NIC,Name),
CONSTRAINT FIR_FK3 FOREIGN KEY(Case_ID)
REFERENCES Case_T(Case_ID));

1 个答案:

答案 0 :(得分:0)

外键的子列和父列的类型是否完全匹配?如果是,表中是否存在违反您尝试添加的外键约束的现有数据?