0

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.

  • post the reference table schema as well – Rahul Sep 26 '16 at 19:37
  • I added a screenshot at the end of the post. Do you mean this? – Imaginario27 Sep 26 '16 at 19:45
  • Your posted screen pic shows that table has already been created. Again don't post pic rather post the schema in text format – Rahul Sep 26 '16 at 19:48
  • I am having the problem at the forward engineer phase. There is always this Error 1215 when I try to export the schema to the database. Where do I find the schema in text format? I don't know what do you mean exactly. – Imaginario27 Sep 26 '16 at 21:20
  • Problem solved. I deleted all tables from the database and did the forward engineer again. – Imaginario27 Sep 27 '16 at 09:15

0 Answers0