如果引擎是 MyISAM,则表中没有外键

2022-01-05 00:00:00 php mysql phpmyadmin

为什么我不能在我的表支付中创建外键.

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;

奥德表是

 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;

推荐答案

因为 MyISAM 不支持外键.FK 声明被解析,但被忽略.您需要使用 InnoDB 表来获得真正的 FK 支持.

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.

相关文章