浏览文章
文章信息
Magento2 清空测试数据|Magento2.3.3
11989
1、忽略(解锁)数据库表关联
SET FOREIGN_KEY_CHECKS = 0;2、清空产品相关数据
要清除所有与产品相关的测试数据(即产品,库存,可下载的链接,URL重写),请运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `catalog_category_product`; TRUNCATE TABLE `catalog_category_product_index`; TRUNCATE TABLE `catalog_category_product_index_tmp`; TRUNCATE TABLE `catalog_compare_item`; TRUNCATE TABLE `catalog_product_bundle_option`; TRUNCATE TABLE `catalog_product_bundle_option_value`; TRUNCATE TABLE `catalog_product_bundle_price_index`; TRUNCATE TABLE `catalog_product_bundle_selection`; TRUNCATE TABLE `catalog_product_bundle_selection_price`; TRUNCATE TABLE `catalog_product_bundle_stock_index`; TRUNCATE TABLE `catalog_product_entity`; TRUNCATE TABLE `catalog_product_entity_datetime`; TRUNCATE TABLE `catalog_product_entity_decimal`; TRUNCATE TABLE `catalog_product_entity_gallery`; TRUNCATE TABLE `catalog_product_entity_int`; TRUNCATE TABLE `catalog_product_entity_media_gallery`; TRUNCATE TABLE `catalog_product_entity_media_gallery_value`; TRUNCATE TABLE `catalog_product_entity_media_gallery_value_to_entity`; TRUNCATE TABLE `catalog_product_entity_media_gallery_value_video`; TRUNCATE TABLE `catalog_product_entity_text`; TRUNCATE TABLE `catalog_product_entity_tier_price`; TRUNCATE TABLE `catalog_product_entity_varchar`; TRUNCATE TABLE `catalog_product_index_eav`; TRUNCATE TABLE `catalog_product_index_eav_decimal`; TRUNCATE TABLE `catalog_product_index_eav_decimal_idx`; TRUNCATE TABLE `catalog_product_index_eav_decimal_tmp`; TRUNCATE TABLE `catalog_product_index_eav_idx`; TRUNCATE TABLE `catalog_product_index_eav_tmp`; TRUNCATE TABLE `catalog_product_index_price`; TRUNCATE TABLE `catalog_product_index_price_bundle_idx`; TRUNCATE TABLE `catalog_product_index_price_bundle_opt_idx`; TRUNCATE TABLE `catalog_product_index_price_bundle_opt_tmp`; TRUNCATE TABLE `catalog_product_index_price_bundle_sel_idx`; TRUNCATE TABLE `catalog_product_index_price_bundle_sel_tmp`; TRUNCATE TABLE `catalog_product_index_price_bundle_tmp`; TRUNCATE TABLE `catalog_product_index_price_cfg_opt_agr_idx`; TRUNCATE TABLE `catalog_product_index_price_cfg_opt_agr_tmp`; TRUNCATE TABLE `catalog_product_index_price_cfg_opt_idx`; TRUNCATE TABLE `catalog_product_index_price_cfg_opt_tmp`; TRUNCATE TABLE `catalog_product_index_price_downlod_idx`; TRUNCATE TABLE `catalog_product_index_price_downlod_tmp`; TRUNCATE TABLE `catalog_product_index_price_final_idx`; TRUNCATE TABLE `catalog_product_index_price_final_tmp`; TRUNCATE TABLE `catalog_product_index_price_idx`; TRUNCATE TABLE `catalog_product_index_price_opt_agr_idx`; TRUNCATE TABLE `catalog_product_index_price_opt_agr_tmp`; TRUNCATE TABLE `catalog_product_index_price_opt_idx`; TRUNCATE TABLE `catalog_product_index_price_opt_tmp`; TRUNCATE TABLE `catalog_product_index_price_tmp`; TRUNCATE TABLE `catalog_product_index_tier_price`; TRUNCATE TABLE `catalog_product_index_website`; TRUNCATE TABLE `catalog_product_link`; TRUNCATE TABLE `catalog_product_link_attribute`; TRUNCATE TABLE `catalog_product_link_attribute_decimal`; TRUNCATE TABLE `catalog_product_link_attribute_int`; TRUNCATE TABLE `catalog_product_link_attribute_varchar`; TRUNCATE TABLE `catalog_product_link_type`; TRUNCATE TABLE `catalog_product_option`; TRUNCATE TABLE `catalog_product_option_price`; TRUNCATE TABLE `catalog_product_option_title`; TRUNCATE TABLE `catalog_product_option_type_price`; TRUNCATE TABLE `catalog_product_option_type_title`; TRUNCATE TABLE `catalog_product_option_type_value`; TRUNCATE TABLE `catalog_product_relation`; TRUNCATE TABLE `catalog_product_super_attribute`; TRUNCATE TABLE `catalog_product_super_attribute_label`; TRUNCATE TABLE `catalog_product_super_link`; TRUNCATE TABLE `catalog_product_website`; TRUNCATE TABLE `catalog_url_rewrite_product_category`; TRUNCATE TABLE `cataloginventory_stock` # 回填默认仓库 INSERT INTO `cataloginventory_stock`(`stock_id`, `website_id`, `stock_name`) VALUES (1,0,'Default'); TRUNCATE TABLE `cataloginventory_stock_item`; TRUNCATE TABLE `cataloginventory_stock_status`; TRUNCATE TABLE `cataloginventory_stock_status_idx`; TRUNCATE TABLE `cataloginventory_stock_status_tmp`; TRUNCATE TABLE `inventory_reservation`; TRUNCATE TABLE `inventory_low_stock_notification_configuration`; TRUNCATE TABLE `downloadable_link`; TRUNCATE TABLE `downloadable_link_price`; TRUNCATE TABLE `downloadable_link_purchased`; TRUNCATE TABLE `downloadable_link_purchased_item`; TRUNCATE TABLE `downloadable_link_title`; TRUNCATE TABLE `downloadable_sample`; TRUNCATE TABLE `downloadable_sample_title`; TRUNCATE TABLE `product_alert_price`; TRUNCATE TABLE `product_alert_stock`; TRUNCATE TABLE `report_compared_product_index`; TRUNCATE TABLE `report_viewed_product_aggregated_daily`; TRUNCATE TABLE `report_viewed_product_aggregated_monthly`; TRUNCATE TABLE `report_viewed_product_aggregated_yearly`; TRUNCATE TABLE `report_viewed_product_index`; SET FOREIGN_KEY_CHECKS = 1;3、清理所有类别
要清除所有测试类别,请运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `catalog_category_entity`; TRUNCATE TABLE `catalog_category_entity_datetime`; TRUNCATE TABLE `catalog_category_entity_decimal`; TRUNCATE TABLE `catalog_category_entity_int`; TRUNCATE TABLE `catalog_category_entity_text`; TRUNCATE TABLE `catalog_category_entity_varchar`; TRUNCATE TABLE `catalog_category_product`; TRUNCATE TABLE `catalog_category_product_index`; TRUNCATE TABLE `catalog_category_product_index_tmp`; INSERT INTO `catalog_category_entity` (`entity_id`, `attribute_set_id`, `parent_id`, `created_at`, `updated_at`, `path`, `position`, `level`, `children_count`) VALUES (1, 0, 0, '2018-03-29 00:00:59', '2018-03-29 00:00:59', '1', 0, 0, 1); SET FOREIGN_KEY_CHECKS = 1;4、清理所有客户
要清除所有与客户相关的测试数据(例如,客户,帐单地址,送货地址),请运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; DELETE FROM `customer_address_entity`; ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1; TRUNCATE TABLE `customer_address_entity_datetime`; TRUNCATE TABLE `customer_address_entity_decimal`; TRUNCATE TABLE `customer_address_entity_int`; TRUNCATE TABLE `customer_address_entity_text`; TRUNCATE TABLE `customer_address_entity_varchar`; DELETE FROM `customer_entity`; ALTER TABLE `customer_entity` AUTO_INCREMENT=1; TRUNCATE TABLE `customer_entity_datetime`; TRUNCATE TABLE `customer_entity_decimal`; TRUNCATE TABLE `customer_entity_int`; TRUNCATE TABLE `customer_entity_text`; TRUNCATE TABLE `customer_entity_varchar`; TRUNCATE TABLE `customer_grid_flat`; TRUNCATE TABLE `customer_log`; TRUNCATE TABLE `customer_visitor`; TRUNCATE TABLE `persistent_session`; SET FOREIGN_KEY_CHECKS = 1;5、清理所有愿望清单
要清除所有测试愿望清单,请运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; DELETE FROM `wishlist`; ALTER TABLE `wishlist` AUTO_INCREMENT=1; DELETE FROM `wishlist_item`; ALTER TABLE `wishlist_item` AUTO_INCREMENT=1; TRUNCATE TABLE `wishlist_item_option`; ALTER TABLE `wishlist` AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS = 1;6、清理所有评论
要清除所有测试评论,请运行以下SQL查询,
SET FOREIGN_KEY_CHECKS = 0; DELETE FROM `review`; ALTER TABLE `review` AUTO_INCREMENT=1; TRUNCATE TABLE `review_detail`; DELETE FROM `review_entity`; ALTER TABLE `review_entity` AUTO_INCREMENT=1; TRUNCATE TABLE `review_entity_summary`; DELETE FROM `review_status` ALTER TABLE `review_status` AUTO_INCREMENT=1; TRUNCATE TABLE `review_store`; SET FOREIGN_KEY_CHECKS = 1;7、清除所有搜索结果
要清除所有测试搜索结果,请运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; DELETE FROM `search_query`; ALTER TABLE `search_query` AUTO_INCREMENT=1; TRUNCATE TABLE `catalogsearch_recommendations`; TRUNCATE TABLE `catalogsearch_fulltext_scope1`; TRUNCATE TABLE `search_synonyms`; SET FOREIGN_KEY_CHECKS = 1;8、清理所有订单
清理所有与订单相关的测试数据(即报价,订单,发票,装运和信用额度),运行以下SQL查询
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `gift_message`; DELETE from `quote`; ALTER TABLE `quote` AUTO_INCREMENT=1; DELETE from `quote_address`; ALTER TABLE `quote_address` AUTO_INCREMENT=1; TRUNCATE TABLE `quote_address_item`; TRUNCATE TABLE `quote_id_mask`; TRUNCATE TABLE `quote_item`; TRUNCATE TABLE `quote_item_option`; TRUNCATE TABLE `quote_payment`; TRUNCATE TABLE `quote_shipping_rate`; TRUNCATE TABLE `reporting_orders`; TRUNCATE TABLE `sales_bestsellers_aggregated_daily`; TRUNCATE TABLE `sales_bestsellers_aggregated_monthly`; TRUNCATE TABLE `sales_bestsellers_aggregated_yearly`; TRUNCATE TABLE `sales_creditmemo`; TRUNCATE TABLE `sales_creditmemo_comment`; TRUNCATE TABLE `sales_creditmemo_grid`; TRUNCATE TABLE `sales_creditmemo_item`; TRUNCATE TABLE `sales_invoice`; TRUNCATE TABLE `sales_invoiced_aggregated`; TRUNCATE TABLE `sales_invoiced_aggregated_order`; TRUNCATE TABLE `sales_invoice_comment`; TRUNCATE TABLE `sales_invoice_grid`; TRUNCATE TABLE `sales_invoice_item`; TRUNCATE TABLE `sales_order`; TRUNCATE TABLE `sales_order_address`; TRUNCATE TABLE `sales_order_aggregated_created`; TRUNCATE TABLE `sales_order_aggregated_updated`; TRUNCATE TABLE `sales_order_grid`; TRUNCATE TABLE `sales_order_item`; TRUNCATE TABLE `sales_order_payment`; TRUNCATE TABLE `sales_order_status_history`; TRUNCATE TABLE `sales_order_tax`; TRUNCATE TABLE `sales_order_tax_item`; TRUNCATE TABLE `sales_payment_transaction`; TRUNCATE TABLE `sales_refunded_aggregated`; TRUNCATE TABLE `sales_refunded_aggregated_order`; TRUNCATE TABLE `sales_shipment`; TRUNCATE TABLE `sales_shipment_comment`; TRUNCATE TABLE `sales_shipment_grid`; TRUNCATE TABLE `sales_shipment_item`; TRUNCATE TABLE `sales_shipment_track`; TRUNCATE TABLE `sales_shipping_aggregated`; TRUNCATE TABLE `sales_shipping_aggregated_order`; TRUNCATE TABLE `tax_order_aggregated_created`; TRUNCATE TABLE `tax_order_aggregated_updated`; ALTER TABLE `sales_order` AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS = 1;9、重置所有属性增量ID
SET FOREIGN_KEY_CHECKS = 0; TRUNCATE `eav_entity_store`; ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1; SET FOREIGN_KEY_CHECKS = 1;