Tengo creada la siguiente estructura de tablas:
Código:
-- CREACION TABLA `CITIES` ( CIUDADES ) CREATE TABLE `CITIES` ( `ID_CITY_PK` INT NOT NULL AUTO_INCREMENT, `CITY` VARCHAR(100), `LATITUDE` FLOAT (10,6) NOT NULL, `LONGITUDE` FLOAT (10,6) NOT NULL, `ID_COUNTRY` INT NOT NULL, PRIMARY KEY (`ID_CITY_PK`), FOREIGN KEY (`ID_COUNTRY`) REFERENCES `COUNTRIES`(`ID_COUNTRY_PK`) ON UPDATE CASCADE ON DELETE CASCADE ); -- CREACION TABLA `COUNTRIES` ( PAISES ) CREATE TABLE `COUNTRIES` ( `ID_COUNTRY_PK` INT NOT NULL AUTO_INCREMENT, `COUNTRY` VARCHAR(100), `LATITUDE` FLOAT (10,6) NOT NULL, `LONGITUDE` FLOAT (10,6) NOT NULL, `ID_CONTINENT` INT NOT NULL, PRIMARY KEY (`ID_COUNTRY_PK`), FOREIGN KEY (`ID_CONTINENT`) REFERENCES `CONTINENTS`(`ID_CONTINENT_PK`) ON UPDATE CASCADE ON DELETE CASCADE ); -- CREACION TABLA `CONTINENTS` ( CONTINENTES ) CREATE TABLE `CONTINENTS` ( `ID_CONTINENT_PK` INT NOT NULL AUTO_INCREMENT, `CONTINENT` VARCHAR(100), `LATITUDE` FLOAT (10,6) NOT NULL, `LONGITUDE` FLOAT (10,6) NOT NULL, PRIMARY KEY (`ID_CONTINENT_PK`) ); -- CREACION TABLA `USERS` ( USUARIOS ) CREATE TABLE `USERS` ( `ID_USER_PK` INT NOT NULL AUTO_INCREMENT, `NAME` VARCHAR(40), `EMAIL` VARCHAR(40), `PASSWORD` VARCHAR(20), `ID_CITY` INT NOT NULL, PRIMARY KEY (`ID_USER_PK`), FOREIGN KEY (`ID_CITY`) REFERENCES `CITIES`(`ID_CITY_PK`) ON UPDATE CASCADE ON DELETE CASCADE );
Al realizar los inserts en el siguiente orden me funciona correctamente (me da un warning, pero creo que es por el FLOAT (10,6), pero este no es el problema)
Código:
El Problema es que el ON UPDATE CASCADE ON DELETE CASCADE no se modifican en las tablas correspondientes y me aparece siempre un 0.INSERT INTO `CONTINENTS` (`ID_CONTINENT_PK`, `CONTINENT`, `LATITUDE`, `LONGITUDE`) VALUES ('','Europa','54.525961','15.255119'); INSERT INTO `COUNTRIES` (`ID_COUNTRY_PK`, `COUNTRY`, `LATITUDE`, `LONGITUDE`, `ID_CONTINENT`) VALUES ('','España','40.463667','-3.74922',''); INSERT INTO `CITIES` (`ID_CITY_PK`, `CITY`, `LATITUDE`, `LONGITUDE`, `ID_COUNTRY`) VALUES ('','Barcelona','41.387917','2.169919',''); INSERT INTO `USERS` (`ID_USER_PK`,`NAME`,`EMAIL`,`PASSWORD`,`ID_CITY`) VALUES ('', 'Manuel Fernandez','[email protected]','123456','Barcelona');
Alguna idea?