如何解决这个问题 - 无法删除或更新父行:外键约束失败 [英] how to solve this- Cannot delete or update a parent row: a foreign key constraint fails
本文介绍了如何解决这个问题 - 无法删除或更新父行:外键约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除表,但出现此错误:
I'm trying to drop table and I'm getting this error :
无法删除或更新父行:外键约束失败
Cannot delete or update a parent row: a foreign key constraint fails
有些人可以帮助我:
语句:DROP TABLE vehiculo
错误:#1217 - 无法删除或更新父行:外键约束失败
与vehiculo有关系的表:
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
推荐答案
您有一个表,该表依赖于该表中的数据,并且阻止删除或删除该行.如果您发现任何依赖于它的表,您可以删除它们,或删除约束,然后删除车辆表.
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.
这篇关于如何解决这个问题 - 无法删除或更新父行:外键约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文