问题
I'm trying to drop table and I'm getting this error :
Cannot delete or update a parent row: a foreign key constraint fails
Some could help me please :
the statement : DROP TABLE vehiculo
the error : #1217 - Cannot delete or update a parent row: a foreign key constraint fails
the tables that have a relationship with vehiculo:
CREATE TABLE `vehiculo` (
`numero_movil` int(3) unsigned NOT NULL,
`numeroChasis` varchar(30) COLLATE utf8_spanish2_ci NOT NULL,
`numeroMotor` varchar(30) COLLATE utf8_spanish2_ci NOT NULL,
`Marca` varchar(15) COLLATE utf8_spanish2_ci NOT NULL,
`Modelo` smallint(5) unsigned NOT NULL,
`Color` varchar(10) COLLATE utf8_spanish2_ci NOT NULL,
`Propietario_Cedula` int(11) NOT NULL,
`Cuota` int(11) NOT NULL,
`Turno_idTurno` tinyint(3) unsigned NOT NULL,
`estado_pago_central` int(11) NOT NULL,
`DocumentoVehiculo` int(10) unsigned NOT NULL,
`f_numero_movil` int(10) unsigned NOT NULL,
`f_Propietario_Cedula` int(11) NOT NULL,
`idEstadoPapelesVehiculo` tinyint(3) unsigned NOT NULL,
`placa` varchar(8) COLLATE utf8_spanish2_ci NOT NULL,
PRIMARY KEY (`numero_movil`,`Propietario_Cedula`,`Turno_idTurno`,`estado_pago_central`,`DocumentoVehiculo`,`f_numero_movil`,`f_Propietario_Cedula`,`idEstadoPapelesVehiculo`),
UNIQUE KEY `numeroChasis_UNIQUE` (`numeroChasis`),
UNIQUE KEY `numeroMotor_UNIQUE` (`numeroMotor`),
KEY `fk_Vehiculo_Propietario1_idx` (`Propietario_Cedula`),
KEY `fk_Vehiculo_Turno1_idx` (`Turno_idTurno`),
KEY `fk_Vehiculo_estado_pago_central1_idx` (`estado_pago_central`),
KEY `fk_Vehiculo_DocumentosVehiculo1_idx` (`DocumentoVehiculo`,`f_numero_movil`,`f_Propietario_Cedula`,`idEstadoPapelesVehiculo`),
CONSTRAINT `fk_Vehiculo_DocumentosVehiculo1` FOREIGN KEY (`DocumentoVehiculo`, `f_numero_movil`, `f_Propietario_Cedula`, `idEstadoPapelesVehiculo`) REFERENCES `documentosvehiculo` (`idDocumentoVehiculo`, `Vehiculo_numero_movil`, `Vehiculo_Propietario_Cedula`, `EstadoPapelesVehiculo_idEstadoPapelesVehiculo`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Vehiculo_estado_pago_central1` FOREIGN KEY (`estado_pago_central`) REFERENCES `estado_pago_central` (`idestado`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Vehiculo_Turno1` FOREIGN KEY (`Turno_idTurno`) REFERENCES `turno` (`idTurno`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `vehiculo_ibfk_1` FOREIGN KEY (`Propietario_Cedula`) REFERENCES `propietario` (`Cedula`) ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci
CREATE TABLE `estadopapelesvehiculo` ( `idEstadoPapelesVehiculo` tinyint(3) unsigned NOT NULL, `EstadoPapelesVehiculocol` varchar(45) COLLATE utf8_spanish2_ci NOT NULL, PRIMARY KEY (`idEstadoPapelesVehiculo`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci
CREATE TABLE `propietario` ( `Cedula` int(11) NOT NULL, `apellidos` varchar(30) COLLATE utf8_spanish2_ci NOT NULL, `nombre` varchar(30) COLLATE utf8_spanish2_ci NOT NULL, `fechaNacimiento` date NOT NULL, PRIMARY KEY (`Cedula`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci
回答1:
You have a table that depends on data that is inside that table, and is preventing a drop or delete of that row. IF you find whatever tables depend on it, you can drop them, or remove the constraints, and then drop the vehicle table.
来源:https://stackoverflow.com/questions/15203742/how-to-solve-this-cannot-delete-or-update-a-parent-row-a-foreign-key-constrain