0

I am trying to clear all test orders from Magento 2.2.x using this SQL query in my PHPMyAdmin but I'm getting an error.
Here's the query I am running:

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE `sales_order`;
TRUNCATE `sendfriend_log`;
TRUNCATE `wishlist`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

The error I am getting is:

SQL query:

TRUNCATE `sales_order`
MySQL said: Documentation

#1701 - Cannot truncate a table referenced in a foreign key constraint (`store`.`downloadable_link_purchased`, CONSTRAINT `DOWNLOADABLE_LINK_PURCHASED_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `store`.`sales_order` (`entity_id`))

2 Answers 2

0

You need to truncate store table first as it is having foreign key

0
0
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE `store`;
TRUNCATE `sales_order`;
TRUNCATE `sendfriend_log`;
TRUNCATE `wishlist`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS = 1;

You can try to below and also set 1 in FOREIGN_KEY_CHECKS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.