Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual MySQL Workbench Error: 1452 foreign key constraint fails?
    primarykey
    data
    text
    <p>Been looking at this for two days and am at a loss as to what this means. I know it means "exactly what it says" but I don't know how to fix it. Can someone explain it to me in layman's terms and help me out?</p> <pre><code>ERROR: Error 1452: Cannot add or update a child row: a foreign key constraint fails (`sls11n`.`dependent`, CONSTRAINT `fk_dependent_employee1` FOREIGN KEY (`emp_id`) REFERENCES `employee` (`emp_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) INSERT INTO `sls11n`.`dependent` (`dep_id`, `emp_id`, `dep_ssn`, `dep_fname`, `dep_lname`, `dep_street`, `dep_city`, `dep_state`, `dep_zip`, `dep_phone`, `dep_email`, `dep_notes`) VALUES (NULL, 13, 123456789, 'Gary', 'Hart', 'West St', 'San Diego', 'CA', '23424', '1234567890', 'garyhart@me.com', NULL) </code></pre> <p>Here's the script that I believe is relevant:</p> <pre><code>-- ----------------------------------------------------- -- Table `sls11n`.`employee` -- ----------------------------------------------------- DROP TABLE IF EXISTS `sls11n`.`employee` ; SHOW WARNINGS; CREATE TABLE IF NOT EXISTS `sls11n`.`employee` ( `emp_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, `emp_ssn` INT UNSIGNED NOT NULL, `emp_fname` VARCHAR(15) NOT NULL, `emp_lname` VARCHAR(20) NOT NULL, `emp_street` VARCHAR(45) NOT NULL, `emp_city` VARCHAR(45) NOT NULL, `emp_state` CHAR(2) NOT NULL, `emp_zip` CHAR(9) NOT NULL, `emp_phone` CHAR(15) NOT NULL, `emp_email` VARCHAR(100) NOT NULL, `emp_doh` DATE NOT NULL, `emp_is_inspect` ENUM('y', 'n') NOT NULL, `emp_notes` VARCHAR(250) NULL, PRIMARY KEY (`emp_id`)) ENGINE = InnoDB; SHOW WARNINGS; -- ----------------------------------------------------- -- Table `sls11n`.`dependent` -- ----------------------------------------------------- DROP TABLE IF EXISTS `sls11n`.`dependent` ; SHOW WARNINGS; CREATE TABLE IF NOT EXISTS `sls11n`.`dependent` ( `dep_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, `emp_id` TINYINT UNSIGNED NOT NULL, `dep_ssn` INT UNSIGNED NOT NULL, `dep_fname` VARCHAR(45) NOT NULL, `dep_lname` VARCHAR(45) NOT NULL, `dep_street` VARCHAR(45) NOT NULL, `dep_city` VARCHAR(45) NOT NULL, `dep_state` CHAR(2) NOT NULL, `dep_zip` CHAR(9) NOT NULL, `dep_phone` CHAR(10) NOT NULL, `dep_email` VARCHAR(100) NOT NULL, `dep_notes` VARCHAR(250) NULL, PRIMARY KEY (`dep_id`), INDEX `fk_dependent_employee1_idx` (`emp_id` ASC), CONSTRAINT `fk_dependent_employee1` FOREIGN KEY (`emp_id`) REFERENCES `sls11n`.`employee` (`emp_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; </code></pre> <p>Any one have any ideas? Please use simple terms, I'm not kidding when I say I don't understand.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload