no foreign key in table if engine is MyISAM

2019-03-04 06:37发布

why i cannot create foreign key in my table payments.

crate table students(
text char(5)NOT NULL,
id int(11)NOT NULL AUTO_INCREMENT,
name varchar(250),
level varchar(250),
PRIMARY KEY (text,id)
)ENGINE=MyISAM;

the oder table is

 crate table payments(
    p_id int(11)NOT NULL AUTO_INCREMENT,
    amount varchar(250),
    id int
    PRIMARY KEY (p_id)
FOREIGN KEY (id) REFERENCES students(id)
    )ENGINE=MyISAM;

1条回答
干净又极端
2楼-- · 2019-03-04 07:05

Because MyISAM does not support foreign keys. The FK declarations are parsed, but otherwise ignored. You need to use InnoDB tables for real FK support.

查看更多
登录 后发表回答