本文介绍了将带有FOREIGN KEY的表添加到MySQL数据库会导致errno 150的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试执行以下SQL,并收到errno:150'无法创建表path_relations'作为响应.根据MySQL文档,这是由于我的FOREIGN KEY约束存在问题而引起的.我在做什么错了?
I'm attemping to execute the following SQL and am receiving errno: 150 'cannot create table path_relations' in response. According to the MySQL documentation this is caused by my FOREIGN KEY restraints having issues. What am I doing wrong?
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;
推荐答案
如果您使paths.id
not 未签名,是否可以正常工作?
Does it work if you make paths.id
not unsigned?
这篇关于将带有FOREIGN KEY的表添加到MySQL数据库会导致errno 150的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!