WordPress级联删除不起作用

时间:2017-12-22 02:16:28

标签: php database wordpress

我需要一些数据库方面的帮助。 好的,我正在创建两个表:

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中的孩子会被自动删除? 但它不起作用。为什么呢?

1 个答案:

答案 0 :(得分: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

相关问题