Si configura ON DELETE SET NULL
a su clave externa, entonces no le permitirá establecer el campo como NOT NULL
.
Por lo tanto, no podrá crear o modificar la tabla con la columna como NOT NULL
y ON DELETE SET NULL
en ID de país
Cuando ejecuto las siguientes declaraciones:
CREATE TABLE `country` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ;
CREATE TABLE `city` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`countryId` int(10) unsigned DEFAULT NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_country` (`countryId`),
CONSTRAINT `FK_country` FOREIGN KEY (`countryId`) REFERENCES `country` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
);
Y obtuve el error en MySQL 5.5
es:
Schema Creation Failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_country` (`countryId`),
CONSTRAINT `' at line 4: