I am trying to create a table named EMPLOYEE. When I use the following statements without \"ON DELETE SET DEFAULT\" it is working.
Here is the Error I get with \"ON
You delete your parent table, which triggers the set default in the child. The DB tries to set the child records to their default 0. But there's no 0 record in the parent table, triggering the foreign key violation.
Check out the MySQL manual about foreign key constrains:
If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.
A few ideas:
ENGINE=InnoDB;
to your CREATE TABLE
- command.SHOW VARIABLES LIKE 'have_innodb';
- if it returns a YES, then InnoDB is enabled."When creating a foreign key constraint, MySQL requires a usable index on both the referencing table and also on the referenced table. The index on the referencing table is created automatically if one doesn't exist, but the one on the referenced table needs to be created manually (Source). Yours appears to be missing."
See MySQL Foreign Key Error 1005 errno 150