As Jens already pointed out, there is an issue with your ticks. First, the identifier quote character in MySQL is the backtick (`) by default, second, you are not using ticks for the table name in your foreign key constraint.
Replace all ticks with backticks and your statement will work (even without ticks around the table name in the foreign key constraint). Leave all ticks out and your statement will work. Change REFERENCES Categorie
to REFERENCES ‘Categorie’
and your statement will work (although probably not as expected).
I would recommend using backticks in all places as a good practice:
CREATE TABLE `Categorie` (
`catID` int(11) NOT NULL AUTO_INCREMENT,
`naam` varchar(20) NOT NULL,
`prioriteit` int(2) NOT NULL,
`subCatVan` int(11) DEFAULT NULL,
PRIMARY KEY (`catID`),
CONSTRAINT `subCatVan` FOREIGN KEY (`subCatVan`) REFERENCES `Categorie`
(`catID`) ON DELETE SET NULL ON UPDATE CASCADE
);
What currently happens is that you are actually not creating a table named Categorie
, but instead a table named ‘Categorie’
(including the ticks). Because you are not using the same ticks in your foreign key constraint, MySQL looks for a table named Categorie
without the ticks and thus cannot find the target for your reference.