Mysql多对多表创建错误:ERROR 1005表存在

时间:2014-08-24 12:49:47

标签: mysql many-to-many relationship

我正在尝试使用连接表建立多对多的关系 但错误:"错误1005:无法创建表' mysql_vb_net_hospital_schema。#sql-8f8_3' (错误:121)"出现

这两张桌子是耐心的,病态的。连接器表是m2m_illness_patient

sick_table的描述:enter image description here

patient_table的描述:enter image description here m2m_illness_patient的描述:enter image description here

我在m2m_illness_patient中添加了2个外键并引用它们

参考疾病表 enter image description here 参考患者表 enter image description here

但错误如下: 错误1005:无法创建表' mysql_vb_net_hospital_schema。#sql-8f8_3' (错误:121)

SQL语句:

ALTER TABLE mysql_vb_net_hospital_schemam2m_illness_patient

添加约束Illness_Id

FOREIGN KEY(Illness_Id

参考mysql_vb_net_hospital_schemaillness_tableIllness_Id

ON DELETE CASCADE

ON UPDATE CASCADE,

添加约束Patient_Id

FOREIGN KEY(Patient_Id

参考mysql_vb_net_hospital_schemapatient_tablePatient_Id

开启删除操作

ON UPDATE NO ACTION

错误:运行故障回复脚本时出错。详情如下。

错误1050:表' m2m_illness_patient'已存在

SQL语句:

CREATE TABLE m2m_illness_patient

Illness_Id int(11)NOT NULL,

Patient_Id int(11)NOT NULL,

PRIMARY KEY(Illness_IdPatient_Id),

KEY Patient_Id_idxPatient_IdIllness_Id

)ENGINE = InnoDB DEFAULT CHARSET = latin1

如何在没有此错误的情况下创建多对多关系?

0 个答案:

没有答案