Pokud nastavíte ON DELETE SET NULL
na váš cizí klíč, pak vám to nedovolí nastavit pole jako NOT NULL
.
Nebudete tedy moci vytvořit nebo upravit tabulku se sloupcem jako NOT NULL
a ON DELETE SET NULL
na CountryId
Když spustím níže uvedené příkazy:
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
);
A dostal jsem chybu v MySQL 5.5
je:
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: