MySQL Forums
Forum List  »  InnoDB

Re: Possible constraint creation
Posted by: GARY BARBER
Date: November 23, 2015 07:01AM

I thought it would possibly be more clear if I used actual table names and fields. Thanks.

Table: vf_sub_dept
+----------------+
| FIELD |
+----------------+
| sub_dept_id |
+----------------+
| dept_id |
+----------------+
| code |
+----------------+
| descr |
+----------------+


Table: vf_dept_config
+----------------+
| FIELD |
+----------------+
| config_dept_id |
+----------------+
| dept_id |
+----------------+
| sub_dept_id |
+----------------+
| emp_off_ttl |
+----------------+
| days_notice |
+----------------+

The alter statement:
ALTER TABLE `vf_dept_config` ADD CONSTRAINT `fk_dept_cfg_sub_id`
FOREIGN KEY (`sub_dept_id`) REFERENCES `vf_sub_dept` (`sub_dept_id`)

The Error:
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails
(`database`.`#sql-2160_60c`, CONSTRAINT `fk_dept_cfg_sub_id` FOREIGN KEY (`sub_dept_id`) REFERENCES `vf_sub_dept` (`sub_dept_id`))

Options: ReplyQuote


Subject
Views
Written By
Posted
1478
November 20, 2015 11:56AM
688
November 20, 2015 12:20PM
797
November 23, 2015 06:20AM
757
November 23, 2015 01:00PM
Re: Possible constraint creation
743
November 23, 2015 07:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.