I'm trying to run this delete script:
DELETE auth, cust
FROM customer cust
JOIN authentication_token auth ON auth.customer_id = cust.id
WHERE cust.email = '[email protected]';
I'm getting the error:
Cannot delete or update a parent row: a foreign key constraint fails (`my_table`.`authentication_token`, CONSTRAINT `authentication_token_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`))
I've tried to change the order of the DELETE statement (cust, auth), and I've tried to change the order of the join, but still the same error.
Is this possible, or will I have to temporary disable constraints?
Table structure:
CREATE TABLE `customer` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`firstName` varchar(255) DEFAULT NULL,
`lastName` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`passwordSalt` varchar(255) DEFAULT NULL,
`phoneNumber` varchar(255) DEFAULT NULL,
`addressLine1` varchar(255) DEFAULT NULL,
`addressLine2` varchar(255) DEFAULT NULL,
`city` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`county` varchar(255) DEFAULT NULL,
`postCode` varchar(255) DEFAULT NULL,
`registeredOn` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `authentication_token` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`value` varchar(255) DEFAULT NULL,
`createdOn` datetime DEFAULT NULL,
`customer_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `customer_id` (`customer_id`),
CONSTRAINT `authentication_token_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`)
)