MySQL错误代码:1451无法删除或更新父行

时间:2015-03-03 08:14:11

标签: mysql doctrine-orm

我在channel表中使用字段parent_id进行自联接。我在表中插入了一行但无法删除它。它给出了错误,如主题中所述。

CREATE TABLE `channels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` int(11) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`channel_type_id` int(11) DEFAULT NULL,
`approval_type_id` int(11) DEFAULT NULL,
`content_type_id` int(11) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`status` tinyint(1) NOT NULL,
`position` int(11) DEFAULT NULL,
`reference_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`mobile` tinyint(1) DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `IDX_F314E2B6C53D045F` (`image`),
 KEY `IDX_F314E2B6727ACA70` (`parent_id`),
 KEY `IDX_F314E2B6720FB392` (`channel_type_id`),
 KEY `IDX_F314E2B6510C33D5` (`approval_type_id`),
 KEY `IDX_F314E2B61A445520` (`content_type_id`),
 CONSTRAINT `FK_F314E2B6727ACA70` FOREIGN KEY (`parent_id`) REFERENCES   `channels` (`id`),
 CONSTRAINT `FK_F314E2B61A445520` FOREIGN KEY (`content_type_id`) REFERENCES `content_type` (`id`),
 CONSTRAINT `FK_F314E2B6510C33D5` FOREIGN KEY (`approval_type_id`) REFERENCES `approval_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `FK_F314E2B6720FB392` FOREIGN KEY (`channel_type_id`) REFERENCES `channel_types` (`id`),
 CONSTRAINT `FK_F314E2B6C53D045F` FOREIGN KEY (`image`) REFERENCES `media__media` (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=6438 DEFAULT CHARSET=utf8        COLLATE=utf8_unicode_ci;

错误如下:

 Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`wenweipo`.`channels`, CONSTRAINT `FK_F314E2B6727ACA70` FOREIGN KEY (`parent_id`) REFERENCES `channels` (`id`))

0 个答案:

没有答案