· 7 years ago · Jan 31, 2019, 04:12 PM
1Executing SQL script in server
2ERROR: Error 1215: Cannot add foreign key constraint
3SQL Code:
4 -- -----------------------------------------------------
5 -- Table `mydb`.`product_audit`
6 -- -----------------------------------------------------
7 CREATE TABLE IF NOT EXISTS `mydb`.`product_audit` (
8 `product_audit_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
9 `staff_id` SMALLINT(5) UNSIGNED NOT NULL,
10 `product_id` MEDIUMINT(8) UNSIGNED NOT NULL,
11 `product_title` VARCHAR(80) NOT NULL,
12 `product_desc` VARCHAR(250) NOT NULL,
13 `product_img_path` CHAR(255) NOT NULL,
14 `product_price` DECIMAL(8,0) UNSIGNED NOT NULL DEFAULT 1000,
15 `product_stock` SMALLINT(255) UNSIGNED NOT NULL DEFAULT 1,
16 `edition_time` TIMESTAMP NOT NULL,
17 `action` ENUM('INSERT', 'UPDATE', 'DELETE') NOT NULL,
18 `product_status` TINYINT UNSIGNED NOT NULL,
19 UNIQUE INDEX `product_title_UNIQUE` (`product_title` ASC),
20 PRIMARY KEY (`product_audit_id`),
21 INDEX `fk_product_audit_staff1_idx` (`staff_id` ASC),
22 INDEX `fk_product_audit_product_status1_idx` (`product_status` ASC),
23 CONSTRAINT `fk_product_audit_staff1`
24 FOREIGN KEY (`staff_id`)
25 REFERENCES `mydb`.`staff` (`staff_id`)
26 ON DELETE NO ACTION
27 ON UPDATE NO ACTION,
28 CONSTRAINT `fk_product_audit_product_status1`
29 FOREIGN KEY (`product_status`)
30 REFERENCES `mydb`.`product_status` (`product_status`)
31 ON DELETE NO ACTION
32 ON UPDATE NO ACTION)
33 ENGINE = InnoDB
34 DEFAULT CHARACTER SET = utf8
35 ROW_FORMAT = DEFAULT
36
37SQL script execution finished: statements: 19 succeeded, 1 failed
38
39Fetching back view definitions in final form.
40Nothing to fetch