MySQL 5.1 not accepting null foreign key from Access 2007 - ms-access

Backend - MySQL 5.1.52 community
Frontend - MS Access 2007
I've got two tables POLIZAS and TRAMITES (both InnoDB)
I'm using Access as the FrontEnd. I need to insert/update records on Tramites where sometimes Tramites is not related to a Polizas yet.
Tramites has a foreign key to Polizas allowing null. But still I get this error when inserting/updating:
[MySQL][ODBC 5.1 Driver][mysqld-5.1.52-community]Cannot add or update a child row: a foreign key constraint fails ('cartera_bd'.'tramites',CONSTRAINT 'fk_tramites_polizas1' FOREIGN KEY ('Poliza') REFERENCES 'polizas' ('Poliza') ON DELETE CASCADE ON UPDATE CASCADE) (#1452)
Any clues?
This is the POLIZAS table description
CREATE TABLE `polizas` (
`Poliza` varchar(20) NOT NULL,
`IdAgente` mediumint(8) unsigned NOT NULL,
`IdPlan` tinyint(3) unsigned NOT NULL,
`IdCliente` int(10) unsigned NOT NULL,
`RenuevaA` varchar(20) DEFAULT NULL,
`InicioVigencia` date NOT NULL,
`IdTipoDerechos` tinyint(1) unsigned NOT NULL,
`IdConducto` tinyint(1) unsigned NOT NULL,
`IdFormaPago` tinyint(1) unsigned NOT NULL,
`IdMoneda` tinyint(1) unsigned NOT NULL,
`PrimaNeta` decimal(11,2) NOT NULL,
`Recargos` decimal(11,2) DEFAULT NULL,
`Derechos` decimal(11,2) DEFAULT NULL,
`IVA` decimal(11,2) DEFAULT NULL,
`PrimaTotal` decimal(11,2) NOT NULL,
`Status` tinyint(1) unsigned NOT NULL,
`Notas` varchar(150) DEFAULT NULL,
`FechaEmision` date DEFAULT NULL,
PRIMARY KEY (`Poliza`),
KEY `IdAgente` (`IdAgente`),
KEY `IdCliente` (`IdCliente`),
KEY `IdConducto` (`IdConducto`),
KEY `IdFormaPago` (`IdFormaPago`),
KEY `IdMoneda` (`IdMoneda`),
KEY `IdPlan` (`IdPlan`),
KEY `IdTipoDerechos` (`IdTipoDerechos`),
KEY `fk_polizas_status1` (`Status`),
CONSTRAINT `fk_polizas_agentes1` FOREIGN KEY (`IdAgente`) REFERENCES `agentes` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_clientes1` FOREIGN KEY (`IdCliente`) REFERENCES `clientes` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_conducto1` FOREIGN KEY (`IdConducto`) REFERENCES `conducto` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_formapago1` FOREIGN KEY (`IdFormaPago`) REFERENCES `formapago` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_moneda1` FOREIGN KEY (`IdMoneda`) REFERENCES `moneda` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_planes1` FOREIGN KEY (`IdPlan`) REFERENCES `planes` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `FK_polizas_status1` FOREIGN KEY (`Status`) REFERENCES `status` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_polizas_tipoderechos1` FOREIGN KEY (`IdTipoDerechos`) REFERENCES `tipoderechos` (`ID`) ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This is the TRAMITES table description
CREATE TABLE `tramites` (
`IdTramite` int(11) NOT NULL AUTO_INCREMENT,
`IdTipoTramite` tinyint(1) unsigned NOT NULL,
`Folio` int(11) DEFAULT NULL,
`Poliza` varchar(20) DEFAULT NULL,
`Inicio` date NOT NULL,
`Fin` date DEFAULT NULL,
`Tramite` text,
`Dias` int(11) DEFAULT NULL,
`IdCliente` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`IdTramite`),
KEY `fk_tramites_polizas1` (`Poliza`),
KEY `fk_tramites_tipotramite1` (`IdTipoTramite`),
KEY `fk_tramites_clientes1` (`IdCliente`) USING BTREE,
CONSTRAINT `fk_tramites_polizas1` FOREIGN KEY (`Poliza`) REFERENCES `polizas` (`Poliza`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `fk_tramites_tipotramite1` FOREIGN KEY (`IdTipoTramite`) REFERENCES `tipotramite` (`Id`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `FK_tramite_clientes1` FOREIGN KEY (`IdCliente`) REFERENCES `clientes` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

Related

SQLError - create foreign key

An error occurred when trying to add a foreign key
SQLError
Before that, the following actions were performed, indexes were installed
maintable
subordinatetable
Acted according to https://folkprog.net/sozdanie-svyazey-phpmyadmin/.
Error text:
ALTER TABLE monoblocks ADD FOREIGN KEY (image_id) REFERENCES monoblock_images(id) ON DELETE RESTRICT ON UPDATE RESTRICT;
#1452 - Cannot add or update a child row: a foreign key constraint fails (myishop.#sql-2150_93, CONSTRAINT #sql-2150_93_ibfk_21 FOREIGN KEY (image_id) REFERENCES monoblock_images (id))
I have found
CREATE TABLE `monoblocks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`goods_id` int(11) NOT NULL,
`screendiagonal_id` int(11) NOT NULL,
`cpu_id` int(11) NOT NULL,
`ramsize_id` int(11) NOT NULL,
`os_id` int(11) NOT NULL,
`hdd_id` int(11) NOT NULL,
`screenresolution_id` int(11) NOT NULL,
`matrixtype_id` int(11) NOT NULL,
`countcpucores` int(11) NOT NULL,
`videocards_id` int(11) NOT NULL,
`videocardtypes_id` int(11) NOT NULL,
`frequency_id` int(11) NOT NULL,
`ramtype_id` int(11) NOT NULL,
`oddtype_id` int(11) NOT NULL,
`bodycolor_id` int(11) NOT NULL,
`weight` int(11) NOT NULL,
`wifisupport_id` int(11) NOT NULL,
`bluetoothsupport_id` int(11) NOT NULL,
`wifistandard_id` int(11) NOT NULL,
`bluetoothstandard_id` int(11) NOT NULL,
`guarantee_id` int(11) NOT NULL,
`connectorsnumberusb2.0` int(11) NOT NULL,
`connectorsnumberusb3.0` int(11) NOT NULL,
`connectorsnumberhdmi` int(11) NOT NULL,
`microphoneconnecors` int(11) NOT NULL,
`headphoneconnectors` int(11) NOT NULL,
`builtinmicrophone` tinyint(1) NOT NULL,
`builtinspeakers` tinyint(1) NOT NULL,
`touchscreen` tinyint(1) NOT NULL,
`webcam` tinyint(1) NOT NULL,
`keyboard_included` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`mouse_included` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`ssd_volume` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`dimensions` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`image_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `goods_id` (`goods_id`),
KEY `screendiagonal_id` (`screendiagonal_id`),
KEY `cpu_id` (`cpu_id`),
KEY `ramsize_id` (`ramsize_id`),
KEY `os_id` (`os_id`),
KEY `hdd` (`hdd_id`),
KEY `screenresolution_id` (`screenresolution_id`),
KEY `matrixtype_id` (`matrixtype_id`),
KEY `countcpucores` (`countcpucores`),
KEY `videocards_id` (`videocards_id`),
KEY `videocardtypes_id` (`videocardtypes_id`),
KEY `frequency_id` (`frequency_id`),
KEY `ramtype_id` (`ramtype_id`),
KEY `oddtype_id` (`oddtype_id`),
KEY `bodycolor_id` (`bodycolor_id`),
KEY `wifisupport_id` (`wifisupport_id`),
KEY `bluetoothsupport_id` (`bluetoothsupport_id`),
KEY `wifistandard_id` (`wifistandard_id`),
KEY `bluetoothstandard_id` (`bluetoothstandard_id`),
KEY `guarantee_id` (`guarantee_id`),
KEY `image_id` (`image_id`),
CONSTRAINT `monoblocks_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_10` FOREIGN KEY (`videocards_id`) REFERENCES `videocards` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_11` FOREIGN KEY (`videocardtypes_id`) REFERENCES `videocardtypes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_12` FOREIGN KEY (`frequency_id`) REFERENCES `cpufrequency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_13` FOREIGN KEY (`ramtype_id`) REFERENCES `rammemory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_14` FOREIGN KEY (`oddtype_id`) REFERENCES `oddtype` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_15` FOREIGN KEY (`bodycolor_id`) REFERENCES `mainbodycolor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_16` FOREIGN KEY (`wifisupport_id`) REFERENCES `wifisupport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_17` FOREIGN KEY (`bluetoothsupport_id`) REFERENCES `bluetoothsupport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_18` FOREIGN KEY (`wifistandard_id`) REFERENCES `wifistandard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_19` FOREIGN KEY (`bluetoothstandard_id`) REFERENCES `bluetoothstandard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_2` FOREIGN KEY (`screendiagonal_id`) REFERENCES `screendiagonal` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_20` FOREIGN KEY (`guarantee_id`) REFERENCES `guarantee` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_3` FOREIGN KEY (`cpu_id`) REFERENCES `cpus` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_4` FOREIGN KEY (`ramsize_id`) REFERENCES `ramsize` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_5` FOREIGN KEY (`os_id`) REFERENCES `os` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_6` FOREIGN KEY (`hdd_id`) REFERENCES `disksandrives` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_7` FOREIGN KEY (`screenresolution_id`) REFERENCES `screenresolution` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_8` FOREIGN KEY (`matrixtype_id`) REFERENCES `matrixtype` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `monoblocks_ibfk_9` FOREIGN KEY (`countcpucores`) REFERENCES `numbercpucores` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `monoblock_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`path_to_image` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
(may be help to answer the question)
In answer on SELECT mb.image_id FROM monoblocks AS mb WHERE NOT EXISTS (SELECT 1 FROM monoblock_images AS i WHERE i.id = mb.image_id) AND mb.image_id IS NOT NULL I gave
monoblockquery
image_id can be NULL in the Table monoblocks but not in the other Table.

Unable to create foreign key constraint MySql

I have 2 tables like these:
'CREATE TABLE `preoperativeassessments` (
`Id` char(36) NOT NULL,
`SurgeonName` varchar(100) NOT NULL,
`SurgeonExperience` int(11) DEFAULT NULL,
`AnesthetistName` varchar(100) DEFAULT NULL,
`DateOfBirthYear` int(11) DEFAULT NULL,
`Gender` int(11) DEFAULT NULL,
`Status` int(11) DEFAULT NULL,
`SurgeryDate` datetime(6) DEFAULT NULL,
`HospitalId` varchar(20) NOT NULL,
`PatientId` varchar(50) NOT NULL,
`SurgeonId` bigint(20) NOT NULL,
`TheaterId` varchar(16) DEFAULT NULL,
`AssessmentDate` datetime(6) DEFAULT NULL,
`BodyStructureId` int(11) NOT NULL,
`MethodId` varchar(100) DEFAULT NULL,
`EthnicityId` int(11) DEFAULT NULL,
PRIMARY KEY (`Id`),
KEY `FK_PreOperativeAssessments_Hospitals_HospitalId_idx` (`HospitalId`),
KEY `FK_PreOperativeAssessments_Patients_PatientId_idx` (`PatientId`),
KEY `FK_PreOperativeAssessments_Users_SurgeonId_idx` (`SurgeonId`),
KEY `FK_PreOperativeAssessments_BodyStructures_BodyStructureId_idx` (`BodyStructureId`),
CONSTRAINT `FK_PreOperativeAssessments_BodyStructures_BodyStructureId` FOREIGN KEY (`BodyStructureId`) REFERENCES `bodystructures` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `FK_PreOperativeAssessments_Hospitals_HospitalId` FOREIGN KEY (`HospitalId`) REFERENCES `hospitals` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `FK_PreOperativeAssessments_Patients_PatientId` FOREIGN KEY (`PatientId`) REFERENCES `patients` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `FK_PreOperativeAssessments_Users_SurgeonId` FOREIGN KEY (`SurgeonId`) REFERENCES `abpusers` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1'
CREATE TABLE `ethnicities` (
`Id` int(11) NOT NULL,
`Description` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
and I try to add foreign key constraint using this:
ALTER TABLE casemix.preoperativeassessments ADD CONSTRAINT FK_PreOperativeAssessments_Ethnicities_EthnicityId FOREIGN KEY (EthnicityId) REFERENCES casemix.ethnicities (Id) ON UPDATE NO ACTION ON DELETE CASCADE
But I keep getting this error: "Error Code: 1215. Cannot add foreign key constraint"
What could be the issue here?
'InnoDB permits a foreign key to reference any index column or group of columns. However, in the referenced table, there must be an index where the referenced columns are the first columns in the same order.' - https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html or a primary key

MySQL Error Code: 1451 Can't Delete or Update Parent Row

I have a self join in the channels table with the field parent_id. I have inserted a row into the table but unable to delete it. Its giving error as stated in the subject.
CREATE TABLE `channels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` int(11) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`channel_type_id` int(11) DEFAULT NULL,
`approval_type_id` int(11) DEFAULT NULL,
`content_type_id` int(11) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`status` tinyint(1) NOT NULL,
`position` int(11) DEFAULT NULL,
`reference_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`mobile` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_F314E2B6C53D045F` (`image`),
KEY `IDX_F314E2B6727ACA70` (`parent_id`),
KEY `IDX_F314E2B6720FB392` (`channel_type_id`),
KEY `IDX_F314E2B6510C33D5` (`approval_type_id`),
KEY `IDX_F314E2B61A445520` (`content_type_id`),
CONSTRAINT `FK_F314E2B6727ACA70` FOREIGN KEY (`parent_id`) REFERENCES `channels` (`id`),
CONSTRAINT `FK_F314E2B61A445520` FOREIGN KEY (`content_type_id`) REFERENCES `content_type` (`id`),
CONSTRAINT `FK_F314E2B6510C33D5` FOREIGN KEY (`approval_type_id`) REFERENCES `approval_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_F314E2B6720FB392` FOREIGN KEY (`channel_type_id`) REFERENCES `channel_types` (`id`),
CONSTRAINT `FK_F314E2B6C53D045F` FOREIGN KEY (`image`) REFERENCES `media__media` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6438 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
The error is as following:
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`wenweipo`.`channels`, CONSTRAINT `FK_F314E2B6727ACA70` FOREIGN KEY (`parent_id`) REFERENCES `channels` (`id`))

Error when updating with foreign keys with ON UPDATE CASCADE

I have this table:
CREATE TABLE `user` (
`idUser` char(13) NOT NULL,
`contrasena` varchar(50) NOT NULL DEFAULT '',
`fechaInicio` datetime DEFAULT NULL,
`emailRegistrado` varchar(100) DEFAULT NULL,
`tipoUsuario` int(11) NOT NULL,
PRIMARY KEY (`idUser`),
KEY `tipoUser` (`tipoUsuario`) USING BTREE,
CONSTRAINT `tipoUser` FOREIGN KEY (`tipoUsuario`) REFERENCES `tipo_user` (`idTipo`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf16;
And then this table:
CREATE TABLE `alumno` (
`idAlumno` char(10) NOT NULL DEFAULT '',
`Nombre` varchar(60) NOT NULL,
`ApePaterno` varchar(30) NOT NULL,
`ApeMaterno` varchar(30) NOT NULL,
`CURP` varchar(18) DEFAULT NULL,
`Sexo` enum('H','M') NOT NULL,
`FechaNac` date NOT NULL,
`Estado_Nac` int(11) DEFAULT NULL,
`Nacionalidad` int(11) DEFAULT NULL,
PRIMARY KEY (`idAlumno`),
KEY `fk_Alumno_Estados1_idx` (`Estado_Nac`) USING BTREE,
KEY `fk_Alumno_Pais1_idx` (`Nacionalidad`) USING BTREE,
CONSTRAINT `fk_Alumno_Estados1` FOREIGN KEY (`Estado_Nac`) REFERENCES `estadomexico` (`idEstados`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Alumno_Pais1` FOREIGN KEY (`Nacionalidad`) REFERENCES `pais` (`idPais`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_Al_User` FOREIGN KEY (`idAlumno`) REFERENCES `user` (`idUser`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf16;
When I try to update a value for a user, MySQL throws the following message:
Cannot delete or update a parent row: a foreign key constraint fails (mydb.empleado, CONSTRAINT fk_Empleado_USer FOREIGN KEY
(idEmpleado) REFERENCES user (idUser) ON DELETE CASCADE ON
UPDATE CASCADE)
Can anybody please help me?

MySQL error when trying to truncate table

I'm having problems to truncate a table on the MySQL Server 5.5.
The table I'm trying to truncate has a column that serves as a foreign key in another table.
The CREATE TABLE of both tables involved is as it follows:
CREATE TABLE `tbluser` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`creationDate` datetime NOT NULL,
`creationUserId` int(11) NOT NULL,
`updateDate` datetime NOT NULL,
`updateUserId` int(11) NOT NULL,
`lastAccess` datetime NOT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
UNIQUE KEY `email_UNIQUE` (`email`),
KEY `FK_tbluser_creationUserId` (`creationUserId`),
KEY `FK_tbluser_updateUserId` (`updateUserId`),
CONSTRAINT `FK_tbluser_updateUserId` FOREIGN KEY (`updateUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_tbluser_creationUserId` FOREIGN KEY (`creationUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
CREATE TABLE `tblpost` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`content` mediumtext NOT NULL,
`creationDate` datetime NOT NULL DEFAULT '1901-01-01 00:00:00',
`creationUserId` int(11) NOT NULL,
`updateDate` datetime NOT NULL DEFAULT '1901-01-01 00:00:00',
`updateUserId` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_tblpost_creationUserId` (`creationUserId`),
KEY `FK_tblpost_updateUserId` (`updateUserId`),
CONSTRAINT `FK_tblpost_updateUserId` FOREIGN KEY (`updateUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_tblpost_creationUserId` FOREIGN KEY (`creationUserId`) REFERENCES `tbluser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Please note that all the constraints are both set to DELETE and UPDATE ON CASCADE.
When I try to TRUNCATE the table:
TRUNCATE TABLE `<databasename>`.`tbluser`;
I receive the following error message:
Cannot truncate a table referenced in a foreign key constraint
(`<databasename>`.`tblpost`,
CONSTRAINT `FK_tblpost_updateUserId`
FOREIGN KEY (`updateUserId`)
REFERENCES `<databasename>`.`tbluser` (`id`))
In addition to this information, there is the fact that when the action above is attempted on a MySQL Server 5.1, it works!
Does anyone have an idea of why this is happening?
Check here . That makes sense that TRUNCATE TABLE raises an error in such cases; the bad thing that it's not documented.