问题描述
我正在尝试导入 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 导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)