我需要一些数据库帮助。好的,我正在创建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
的孩子会被自动删除?但它不起作用。为什么?
我检查了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