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 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
