我需要一些数据库方面的帮助。 好的,我正在创建两个表:
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
中的孩子会被自动删除?
但它不起作用。为什么呢?
答案 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