获取1215错误'无法添加外键约束

时间:2014-11-22 16:36:01

标签: mysql foreign-keys

任何人都可以从我的代码中看到为什么我收到此错误?这对我来说是新的,所以还在学习。感谢

CREATE TABLE DIRECTOR(
DIRECTOR_ID VARCHAR (6) PRIMARY KEY NOT NULL,
F_NAME VARCHAR (10) NOT NULL,
L_NAME VARCHAR (10) NOT NULL);

CREATE TABLE TITLE_DIRECTOR(
TITLE_ID VARCHAR (10) NOT NULL,
DIRECTOR_ID VARCHAR (6) NOT NULL,
TITLE_NAME VARCHAR (50) NOT NULL,
DIRECTOR_FNAME VARCHAR (10) NOT NULL,
DIRECTOR_LNAME VARCHAR (10) NOT NULL,
INDEX (DIRECTOR_ID),
FOREIGN KEY (DIRECTOR_ID) REFERENCES DIRECTOR (DIRECTOR_ID));

1 个答案:

答案 0 :(得分:0)

也许您将MyISAM作为默认引擎,只需将隐式引擎放入InnoDB:

CREATE TABLE DIRECTOR(
  DIRECTOR_ID VARCHAR (6) PRIMARY KEY NOT NULL,
  F_NAME VARCHAR (10) NOT NULL,
  L_NAME VARCHAR (10) NOT NULL
) ENGINE = InnoDB;



CREATE TABLE TITLE_DIRECTOR(
  TITLE_ID VARCHAR (10) NOT NULL,
  DIRECTOR_ID VARCHAR (6) NOT NULL,
  TITLE_NAME VARCHAR (50) NOT NULL,
  DIRECTOR_FNAME VARCHAR (10) NOT NULL,
  DIRECTOR_LNAME VARCHAR (10) NOT NULL,
  INDEX (DIRECTOR_ID),
  FOREIGN KEY (DIRECTOR_ID) REFERENCES DIRECTOR (DIRECTOR_ID)
)ENGINE = InnoDB;;