我是 MYSQL 的新手,正在为我刚开始的新工作做一些培训。我被这个错误困扰了一段时间,想知道是否有人知道我在这里做错了什么。
在服务器中执行 SQL 脚本
ERROR: Error 3780: Referencing column 'product_id' and referenced column 'product_id' in foreign key constraint 'fk_product_has_campaign_description_product1' are incompatible.
SQL Code:
-- -----------------------------------------------------
-- Table `dunnhumby`.`coupon`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `dunnhumby`.`coupon` (
`coupon_upc` BIGINT UNSIGNED NOT NULL,
`product_id` INT UNSIGNED NOT NULL,
`campaign` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`coupon_upc`, `product_id`, `campaign`),
INDEX `fk_product_has_campaign_description_campaign_description1_idx` (`campaign` ASC) VISIBLE,
INDEX `fk_product_has_campaign_description_product1_idx` (`product_id` ASC) VISIBLE,
CONSTRAINT `fk_product_has_campaign_description_product1`
FOREIGN KEY (`product_id`)
REFERENCES `dunnhumby`.`product` (`product_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_product_has_campaign_description_campaign_description1`
FOREIGN KEY (`campaign`)
REFERENCES `dunnhumby`.`campaign_description` (`campaign`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 10 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
我已经尝试进行大量研究,并以多种方式更新了产品 ID 外键,但没有成功。