我在MySQL Server 5.5上截断表时遇到问题.
我正在尝试截断的表有一列作为另一个表中的外键.
涉及的两个表的CREATE TABLE如下:
CREATE TABLE `tbluser` (
`id` int(11) NOT NULL AUTO_INCREMENT,`email` varchar(255) NOT NULL,`password` varchar(255) NOT NULL,`name` varchar(255) NOT NULL,`creationDate` datetime NOT NULL,`creationUserId` int(11) NOT NULL,`updateDate` datetime NOT NULL,`updateUserId` int(11) NOT NULL,`lastAccess` datetime NOT NULL,`enabled` tinyint(1) NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `id_UNIQUE` (`id`),UNIQUE KEY `email_UNIQUE` (`email`),KEY `FK_tbluser_creationUserId` (`creationUserId`),KEY `FK_tbluser_updateUserId` (`updateUserId`),CONSTRAINT `FK_tbluser_updateUserId` FOREIGN KEY (`updateUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT `FK_tbluser_creationUserId` FOREIGN KEY (`creationUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
CREATE TABLE `tblpost` (
`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(255) NOT NULL,`content` mediumtext NOT NULL,`creationDate` datetime NOT NULL DEFAULT '1901-01-01 00:00:00',`updateDate` datetime NOT NULL DEFAULT '1901-01-01 00:00:00',KEY `FK_tblpost_creationUserId` (`creationUserId`),KEY `FK_tblpost_updateUserId` (`updateUserId`),CONSTRAINT `FK_tblpost_updateUserId` FOREIGN KEY (`updateUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT `FK_tblpost_creationUserId` FOREIGN KEY (`creationUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
请注意,所有约束都设置为DELETE和UPDATE ON CASCADE.
当我尝试TRUNCATE表时:
TRUNCATE TABLE `
我收到以下错误消息:
Cannot truncate a table referenced in a foreign key constraint
(`
除了这些信息之外,还有一个事实是,当在MysqL Server 5.1上尝试上述操作时,它可以工作!
有没有人知道为什么会这样?
最佳答案