MySQL ON UPDATE/ON DELETE CASCADE 不是 CASCADE
当我编辑注册表上的 UID 时,客户端表上的parentid 列应该会更改。它不是这样做的。有什么建议吗?
客户
CREATE TABLE `clients` (
`id` INT(255) NOT NULL AUTO_INCREMENT,
`fname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`lname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`email` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`phone` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`parentid` INT(255) NOT NULL,
`hphone` VARCHAR(12) NOT NULL COLLATE 'latin1_bin',
`postal` VARCHAR(10) NOT NULL COLLATE 'latin1_bin',
`city` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`address` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`country` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`sms` INT(1) NOT NULL,
`semail` INT(1) NOT NULL,
`gender` VARCHAR(6) NOT NULL COLLATE 'latin1_bin',
`bday` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`bmonth` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
PRIMARY KEY (`id`),
INDEX `parentid` (`parentid`),
CONSTRAINT `FK_clients_signup` FOREIGN KEY (`parentid`) REFERENCES `signup` (`UID`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=31751
注册
CREATE TABLE `signup` (
`UID` INT(255) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`hash` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`email` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`fname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`lname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`address` TEXT NOT NULL COLLATE 'latin1_bin',
`city` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`zip` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`country` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`company` TEXT NOT NULL COLLATE 'latin1_bin',
`addtime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`logintime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`user_ip` VARCHAR(16) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`pwd` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`credits` INT(255) NOT NULL,
`plan` INT(255) NOT NULL DEFAULT '1',
`reset` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`expires` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`afid` INT(255) NOT NULL,
`industryid` INT(255) NOT NULL,
PRIMARY KEY (`UID`),
UNIQUE INDEX `email` (`email`),
UNIQUE INDEX `username` (`username`),
INDEX `industryid` (`industryid`),
INDEX `afid` (`afid`),
INDEX `plan` (`plan`),
CONSTRAINT `FK_signup_affiliates` FOREIGN KEY (`afid`) REFERENCES `affiliates` (`afid`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_signup_plans` FOREIGN KEY (`plan`) REFERENCES `plans` (`pid`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=27
When I edit UID on the signup table, the parentid column on the clients table is supposed to change. It's not doing that. Any suggestions?
Clients
CREATE TABLE `clients` (
`id` INT(255) NOT NULL AUTO_INCREMENT,
`fname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`lname` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`email` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`phone` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`parentid` INT(255) NOT NULL,
`hphone` VARCHAR(12) NOT NULL COLLATE 'latin1_bin',
`postal` VARCHAR(10) NOT NULL COLLATE 'latin1_bin',
`city` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`address` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`country` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`sms` INT(1) NOT NULL,
`semail` INT(1) NOT NULL,
`gender` VARCHAR(6) NOT NULL COLLATE 'latin1_bin',
`bday` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`bmonth` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
PRIMARY KEY (`id`),
INDEX `parentid` (`parentid`),
CONSTRAINT `FK_clients_signup` FOREIGN KEY (`parentid`) REFERENCES `signup` (`UID`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=31751
Signup
CREATE TABLE `signup` (
`UID` INT(255) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`hash` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`email` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`fname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`lname` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`address` TEXT NOT NULL COLLATE 'latin1_bin',
`city` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`province` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`zip` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`country` VARCHAR(80) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`company` TEXT NOT NULL COLLATE 'latin1_bin',
`addtime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`logintime` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`user_ip` VARCHAR(16) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`pwd` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`credits` INT(255) NOT NULL,
`plan` INT(255) NOT NULL DEFAULT '1',
`reset` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`expires` VARCHAR(255) NOT NULL COLLATE 'latin1_bin',
`afid` INT(255) NOT NULL,
`industryid` INT(255) NOT NULL,
PRIMARY KEY (`UID`),
UNIQUE INDEX `email` (`email`),
UNIQUE INDEX `username` (`username`),
INDEX `industryid` (`industryid`),
INDEX `afid` (`afid`),
INDEX `plan` (`plan`),
CONSTRAINT `FK_signup_affiliates` FOREIGN KEY (`afid`) REFERENCES `affiliates` (`afid`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `FK_signup_plans` FOREIGN KEY (`plan`) REFERENCES `plans` (`pid`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='latin1_bin'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=27
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能不会改变,因为您不可能更改注册表上的 UID,因为它是主键,并且自动递增
It's probably not changing because you can't possibly change the UID on the signup table since it's the primary key, and is auto incremented