我正在尝试执行以下 SQL 并收到 errno: 150 'cannot create table path_relations' 作为响应。根据 MySQL 文档,这是由我的 FOREIGN KEY 限制有问题引起的。我究竟做错了什么?
DROP TABLE IF EXISTS `paths`;
DROP TABLE IF EXISTS `path_relations`;
CREATE TABLE `paths` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(256) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `path_relations` (
`ancestor` int(11) NOT NULL DEFAULT '0',
`descendant` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY(`ancestor`, `descendant`),
FOREIGN KEY(`ancestor`) REFERENCES paths(`id`),
FOREIGN KEY(`descendant`) REFERENCES paths(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;