LoginSignup
2
1

More than 5 years have passed since last update.

EC-CUBE3での商品データ削除(by SQL)

Posted at

EC-CUBE3で商品情報をデータベースから一括削除したいなと思ったのですが、普通にTRUNCATEしたら
こんなエラーがでて出来ませんでした...

Cannot truncate a table referenced in a foreign key constraint (`bikers-jp_rb`.`dtb_product_class`, CONSTRAINT `FK_1A11D1BA4584665A` FOREIGN KEY (`product_id`) REFERENCES `bikers-jp_rb`.`dtb_product` (`product_id`))

外部キー制約なるものがかかっているとのことで調べたところこんな方法でできました。

SET foreign_key_checks=0;
TRUNCATE TABLE `dtb_product_category`;
TRUNCATE TABLE `dtb_product_image`;
TRUNCATE TABLE `dtb_product_stock`;
TRUNCATE TABLE `dtb_product_tag`;
TRUNCATE TABLE `dtb_product`;
TRUNCATE TABLE `dtb_product_class`;
SET foreign_key_checks=1;
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1