Foreign key constraint error 1452 in MySQL - Magento import(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 导入
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
