MySQL :erreur 150 en utilisant ON UPDATE SET NULL et ON DELETE SET NULL, pourquoi ?

StackOverflow https://stackoverflow.com/questions/4992488

  •  13-11-2019
  •  | 
  •  

Question

J'ai ceci:

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;

et j'obtiens cette erreur :

1005 - Impossible de créer la table 'prueba1.shop_orders' (errno:150)

si je ne supprime pas les lignes ON UPDATE SET NULL et ON DELETE SET NULL.

Une idée de pourquoi ?

Salutations

Java

Était-ce utile?

La solution

Je pense que c'est parce que tu as déclaré le champ NOT NULL

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top