MySQL 中的外键约束错误 1452 - Magento 导入

Foreign key constraint error 1452 in MySQL - Magento import(MySQL 中的外键约束错误 1452 - Magento 导入)

本文介绍了MySQL 中的外键约束错误 1452 - Magento 导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入 magento 的 sql 转储以及一些产品数据,但出现此外键约束错误:

i am trying to import a sql dump of magento along with some product data and i get this foreign key constraint error:

`ERROR 1452 (23000) at line 231680: Cannot add or update a child row: a foreign key constraint fails:
`magento`.`#sql-b33_27`, CONSTRAINT `FK_CATALOG_COMPARE_ITEM_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON )`

这是导致错误的sql代码:

This is the sql code which is causing the error :

--
-- Constraints for table `catalog_eav_attribute`
--
ALTER TABLE `catalog_eav_attribute`
  ADD CONSTRAINT `FK_CATALOG_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE;

我对 sql 查询不是很满意.有人可以解释一下这个查询的作用并指导我解决这个问题吗?谢谢.

I am not very comfortable with sql queries. Could some one please explain me what this query does and guide me to resolve this? Thanks.

推荐答案

您正在尝试将记录添加到 catalog_eav_attribute,但 eav_attribute 中没有相应的记录> 匹配 attribute_id

You are trying to add a record into catalog_eav_attribute, but you do not have a corresponding record in eav_attribute that matches on attribute_id

如果您还要向 eav_attribute 中插入批量数据,我建议先这样做,然后数据会在需要 catalog_eav_attribute 上的外键之前出现在表中参考一下.

If you are also inserting bulk data into eav_attribute, I would recommend doing that first, and then the data would be in the table before the foreign key on catalog_eav_attribute needed to reference it.

这个文章 讨论了如何使用:

This article discusses how you can use:

SET FOREIGN_KEY_CHECKS = 0;
--Do your update here
SET FOREIGN_KEY_CHECKS = 1;

如果您无法更改插入数据的顺序.在将所有内容插入数据库后,您只需确保您的数据遵循外键,然后才能重新启用 FOREIGN_KEY_CHECKS

If you cannot change the order that you are inserting data. You just have to make sure your data follows the Foreign Keys once everything has been inserted into the database, before you can re-enable the FOREIGN_KEY_CHECKS

这篇关于MySQL 中的外键约束错误 1452 - Magento 导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MySQL 中的外键约束错误 1452 - Magento 导入

基础教程推荐