Я просмотрел другие форумы, в том числе сообщения об этой ошибке, но не могу найти причину ее возникновения в моей ситуации.Типы данных, параметры сортировки, заполнение нулями, ненулевые, беззнаковые и двоичные типы совпадают, и я все еще не могу найти решение.Вывод, который я получаю, выглядит следующим образом:
ошибка: ERROR: Error 1822: Failed to add the foreign key constraint. Missing index for constraint 'fk_projects_has_equipment_equipment1' in the referenced table 'equipment'
Я также включил таблицу оборудования.Любая помощь с благодарностью.
код:
CREATE TABLE IF NOT EXISTS `Group_13_Schema`.`project_equipment` (
`project_id` INT NOT NULL,
`vendor_id` INT NOT NULL,
`department_id` INT NOT NULL,
`equipment_id` INT NOT NULL,
`equipment_cost` DECIMAL(10,2) NULL,
PRIMARY KEY (`department_id`, `equipment_id`, `project_id`, `vendor_id`),
INDEX `fk_projects_has_equipment_equipment1_idx` (`vendor_id` ASC, `department_id` ASC, `equipment_id` ASC) VISIBLE,
INDEX `fk_projects_has_equipment_projects1_idx` (`project_id` ASC) VISIBLE,
CONSTRAINT `fk_projects_has_equipment_projects1`
FOREIGN KEY (`project_id`)
REFERENCES `Group_13_Schema`.`projects` (`project_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_projects_has_equipment_equipment1`
FOREIGN KEY (`vendor_id` , `department_id` , `equipment_id`)
REFERENCES `Group_13_Schema`.`equipment` (`vendor_id` , `department_id` , `equipment_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `Group_13_Schema`.`equipment` (
`equipment_id` INT NOT NULL,
`vendor_id` INT NOT NULL,
`department_id` INT NOT NULL,
`equipment_name` VARCHAR(45) NULL,
`equipment_cost` DECIMAL(10,2) NULL,
PRIMARY KEY (`equipment_id`, `vendor_id`, `department_id`),
INDEX `fk_departments_has_vendors_vendors1_idx` (`vendor_id` ASC) VISIBLE,
INDEX `fk_departments_has_vendors_departments1_idx` (`department_id` ASC) VISIBLE,
CONSTRAINT `fk_departments_has_vendors_departments1`
FOREIGN KEY (`department_id`)
REFERENCES `Group_13_Schema`.`departments` (`department_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_departments_has_vendors_vendors1`
FOREIGN KEY (`vendor_id`)
REFERENCES `Group_13_Schema`.`vendors` (`vendor_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_projects_has_equipment_equipment1`
FOREIGN KEY (`equipment_id`)
REFERENCES `Group_13_Schema`.`equipment` (`vendor_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;