Mysql无法创建表(错误号:150)

时间:2014-11-26 16:08:59

标签: mysql

我尝试使用sql文件导入下面的表格,但是我得到了

#1005 - Can't create table 'ehr_se.patient_medication' (errno: 150)

你能帮我解决一下吗?提前谢谢!

CREATE TABLE IF NOT EXISTS  `ehr_se`.`patient_medication` (

 `patient_medication_id` INT NOT NULL AUTO_INCREMENT ,
 `admission_id` INT NOT NULL ,
 `patient_id` INT NOT NULL ,
 `active_ingredient` VARCHAR( 45 ) NULL ,
 `active_ingredient_id_code` INT NULL ,
 `strength` INT NULL ,
 `pharmaceutical_dose_form` VARCHAR( 45 ) NULL ,
 `number_of_units_per_intake` INT NULL ,
 `frequency_of_intakes` INT NULL ,
 `duration_of_treatment` DATE NULL ,
 `date_of_onset_treatment` DATE NULL ,
 `start_date_of_treatment` DATE NULL ,
PRIMARY KEY (  `patient_medication_id` ) ,
UNIQUE INDEX  `pat_med_id_UNIQUE` (  `patient_medication_id` ASC ) ,
INDEX  `med_admin_data` (  `admission_id` ASC ,  `patient_id` ASC ) ,
CONSTRAINT  `med_adm_data` FOREIGN KEY (  `admission_id` ,  `patient_id` ) REFERENCES  `ehr_se`.`admission_data` (
`admission_id` ,
`patient_id`
) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = INNODB;

2 个答案:

答案 0 :(得分:0)

检查您的参考密钥

`ehr_se`.`admission_data` (
`admission_id` ,
`patient_id`
)

具有确切的类型INT

答案 1 :(得分:0)

解决方案是将表格admission_data,字段admission_idpatient_id作为一个索引。