我要創建一個名爲patientmedicinecategory的表。 ,如下所示: -關於刪除設置null在mysql中創建表格
CREATE TABLE patientmedicinecategory
(
pmc int(11) NOT NULL AUTO_INCREMENT,
patient_id int(11) NOT NULL,
med_id int(3) NOT NULL,
cat_id int(3) NOT NULL,
testname varchar(100) NOT NULL,
PRIMARY KEY(pmc),
UNIQUE KEY(patient_id, med_id,cat_id,testname),
FOREIGN KEY(patient_id) REFERENCES patient(patient_id) ON UPDATE CASCADE ON DELETE
CASCADE,
FOREIGN KEY(med_id) REFERENCES medicine(med_id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(cat_id) REFERENCES category(cat_id) ON UPDATE CASCADE ON DELETE SET NULL
)ENGINE=InnoDB;
我的病人表是: -
CREATE TABLE patient
(
patient_id int NOT NULL AUTO_INCREMENT,
salutation ENUM('Mr.','Mrs.','Miss.','Dr.') NOT NULL,
name varchar(50) NOT NULL,
email_id varchar(100),
year int(4) NOT NULL,
month int(3),
day int(3),
sex ENUM('M','F') NOT NULL,
contactno varchar(50),
PRIMARY KEY(patient_id)
)ENGINE=InnoDb;
醫學表是: -
CREATE TABLE medicine
(
med_id int(3) NOT NULL,
name varchar(40) NOT NULL,
PRIMARY KEY (med_id)
)ENGINE=InnoDB;
分類表是: -
CREATE TABLE category
(
cat_id int(3) NOT NULL,
name varchar(20) NOT NULL,
PRIMARY KEY (cat_id)
)ENGINE=InnoDB;
但當我嘗試創建它時會出現錯誤: -
ERROR 1005 (HY000): Can't create table 'nutech3.patientmedicinecategory' (errno: 150)
我已經嘗試了很多,但無法成功。請幫幫我 。在此先感謝
登錄爲'root'和運行'SHOW ENGINE INNODB STATUS'。 – 2013-04-05 09:31:12
engine = innodb工作正常。它不是problm – 2013-04-05 09:47:20
我覺得這裏來,你正在尋找 [計算器同樣的問題鏈接]解決方案[1] [1]:http://stackoverflow.com/questions/11045279/error-1005-hy000 -cant-create-table-errno-150 – 2013-04-05 09:55:14