sql >> Base de Datos >  >> RDS >> Mysql

ERROR 1215. MySQL InnoDB

Probé la creación de tu tabla.

Luego obtuve más información sobre el error de clave externa:

mysql> show engine innodb status\G

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2018-02-20 14:51:33 700002d90000 Error in foreign key constraint of table calls/called:

    FOREIGN KEY (`Code`)
    REFERENCES `calls`.`city` (`Code`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `Number`
    FOREIGN KEY (`Number`)
    REFERENCES `calls`.`subscriber` (`Number`)
    ON DELETE CASCADE
    ON UPDATE CASCADE):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
...

Veo el problema:tienes una clave primaria compuesta en city en las columnas (Name, Code) . Para ello, debe crear uno restricción de clave externa que hace referencia a ambos columnas de la clave principal del padre.

Así:

CONSTRAINT `Name`
FOREIGN KEY (`Name`, `Code`)
REFERENCES `calls`.`city` (`Name`, `Code`)
ON DELETE CASCADE
ON UPDATE CASCADE

No declare una restricción para cada columna:declare una restricción que haga referencia a ambas columnas de la clave.