I am trying to add a table with 2 foreign keys set as primary key (compound key) with MySQL Workbench. I also tried in phpMyAdmin but the result was the same. With Workbench I am using the forward engineer to add the table from the schema to the database.
This is the sql query created by Workbench:
CREATE TABLE IF NOT EXISTS `img27globalmanager`.`servicios_requeridos_proyectos_mantenimiento_web_proyectos` (
`id_servicio_mantenimiento_web` INT NOT NULL,
`id_proyecto` INT NOT NULL,
INDEX `fk_servicios_requeridos_proyectos_mantenimiento_web_proyect_idx` (`id_servicio_mantenimiento_web` ASC),
INDEX `fk_servicios_requeridos_proyectos_mantenimiento_web_proyect_idx1` (`id_proyecto` ASC),
PRIMARY KEY (`id_servicio_mantenimiento_web`, `id_proyecto`),
CONSTRAINT `fk_servicios_requeridos_proyectos_mantenimiento_web_proyectos1`
FOREIGN KEY (`id_servicio_mantenimiento_web`)
REFERENCES `img27globalmanager`.`servicios_requeridos_proyectos_mantenimiento_web` (`id_servicio_mantenimiento_web`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_servicios_requeridos_proyectos_mantenimiento_web_proyectos2`
FOREIGN KEY (`id_proyecto`)
REFERENCES `img27globalmanager`.`proyectos` (`id_proyecto`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
The table takes 1 primary key field from the table 'Proyectos' and another from 'Servicios_requeridos_proyectos_mantenimiento_web'.
I have more tables with compound keys created the same way but this is the only one that doesn't work.
I have already checked the data type and both foreigh keys fields are the same as they foreign keys: INT / Not Null. I tried to delete and create the table again but didn't work.
Need help please.
I saw some similar posts but their solutions didn't work in my case.