MySQL:使用 ON UPDATE SET NULL 和 ON DELETE SET NULL 时出现错误 150,为什么?
我有这个:
DROP TABLE IF EXISTS `sf_guard_user`;
CREATE TABLE `sf_guard_user`
(
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sf_guard_user_U_1` (`username`)
)Type=InnoDB;
DROP TABLE IF EXISTS `shop_orders`;
CREATE TABLE `shop_orders`
(
`orders_id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`sfgu_id` INTEGER(11) NOT NULL,
PRIMARY KEY (`orders_id`),
INDEX `shop_orders_FI_1` (`sfgu_id`),
CONSTRAINT `shop_orders_FK_1`
FOREIGN KEY (`sfgu_id`)
REFERENCES `sf_guard_user` (`id`)
ON UPDATE SET NULL
ON DELETE SET NULL,
)Type=InnoDB;
并且我收到此错误:
1005 - 无法创建表 'prueba1.shop_orders'(错误号:150)
如果我不删除 ON UPDATE SET NULL 和 ON DELETE SET NULL 行。
知道为什么吗?
问候
哈维
i have this:
DROP TABLE IF EXISTS `sf_guard_user`;
CREATE TABLE `sf_guard_user`
(
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sf_guard_user_U_1` (`username`)
)Type=InnoDB;
DROP TABLE IF EXISTS `shop_orders`;
CREATE TABLE `shop_orders`
(
`orders_id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`sfgu_id` INTEGER(11) NOT NULL,
PRIMARY KEY (`orders_id`),
INDEX `shop_orders_FI_1` (`sfgu_id`),
CONSTRAINT `shop_orders_FK_1`
FOREIGN KEY (`sfgu_id`)
REFERENCES `sf_guard_user` (`id`)
ON UPDATE SET NULL
ON DELETE SET NULL,
)Type=InnoDB;
and I'm getting this error:
1005 - Can't create table
'prueba1.shop_orders' (errno: 150)
if i do not remove the lines ON UPDATE SET NULL and ON DELETE SET NULL.
Any idea why?
Regards
Javi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为您声明了该字段
NOT NULL
I think that is because you declared the field
NOT NULL