WordPress级联删除不起作用

问题描述 投票:1回答:1

我需要一些数据库帮助。好的,我正在创建2个这样的表:

CREATE TABLE inventory_category ( 
    id int NOT NULL AUTO_INCREMENT, 
    name varchar(255) NOT NULL, 
    PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

CREATE TABLE inventory_subcategory(
    id int NOT NULL AUTO_INCREMENT,
    category_id int NOT NULL,
    name varchar(255) NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY  (category_id) REFERENCES inventory_category(id) ON DELETE CASCADE
) ENGINE=MyISAM DEFAULT CHARSET=utf8

如你所见,category_id引用inventory_category id。所以,据我所知,当我在inventory_Category删除某些东西时,他在inventory_subcategory的孩子会被自动删除?但它不起作用。为什么?

php database wordpress
1个回答
0
投票

我检查了Mysql.com,看起来MyISAM for MySQL或MariaDB不支持外键。

https://dev.mysql.com/doc/refman/5.7/en/myisam-storage-engine.html

然而,Innodb引擎可能是你想要的:

https://dev.mysql.com/doc/refman/5.7/en/innodb-storage-engine.html

© www.soinside.com 2019 - 2024. All rights reserved.