MySQL: error 150 using ON UPDATE SET NULL and ON DELETE SET NULL, why?

瘦欲@ 提交于 2019-12-10 14:15:07

问题


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


回答1:


I think that is because you declared the field NOT NULL



来源:https://stackoverflow.com/questions/4992488/mysql-error-150-using-on-update-set-null-and-on-delete-set-null-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!