Wednesday, 15 February 2012

mysql - SQL #1215 - Cannot add foreign key constraint -


I got this code to create an SQL table, though I'm facing error # 1215

Help is appreciated!

As Jane has already said, there is a problem with your ticks First, MySQL In the identifier bidding character bracket (`) is the second by default, you are not ticking to the table name in your foreign key constraint.

Change all the tickets with backticks and leave all the vaccines and your statement will work (even without ticks around the table name in the foreign key barrier) and your statement will work. Replace context and category of category ' and your statement will work (although probably not expected as expected).

I would recommend using Batcot in all places as a good practice:

  create tables` Categorie` (`catID` integer (11) not NULL AUTO_INCREMENT, 'naam` varchar (20) No NULL, `prerequisite` integer (2) zero,` subCatVan` integer (11) default zero, primary key (`catID`), constraint' subCatVan` foreign key (` subCatVan` ) Referred `Categorie` (` catID`) to delete the SET faucet update on CASCADE);  

Is it currently that you are not actually creating a table named category , but instead of 'category' (including a table named) Because you are not using the same tick in your foreign key constraint, therefore MySQL looks like a tick for a table named Categorie and thus The goal for your reference can not be found.


No comments:

Post a Comment