Magento数据库错误:完整性约束违例:1452无法添加或更新子行:外键约束失败 [英] Magento DB Error: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

查看:1776
本文介绍了Magento数据库错误:完整性约束违例:1452无法添加或更新子行:外键约束失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在为magento产品,类别和属性集编写自定义importscript。我知道这是坏的做法,使用裸mysql和php,但这是它的目前的方式。

right now i am writing a custom importscript for magento products, categories and attribute sets. i know it's bad practise to use bare mysql and php, but that's the way it is at the moment.

在创建一个产品与我的自定义函数,这个错误,第一个产品:

while creating a product with my custom functions this error apprears on the very first product:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: 
Integrity constraint violation: 1452 Cannot add or update a child row: 
a foreign key
constraint fails (`shopname`.`cataloginventory_stock_status`, CONSTRAINT 
`FK_CATINV_STOCK_STS_STOCK_ID_CATINV_STOCK_STOCK_ID` FOREIGN KEY (`stock_id`) 
REFERENCES `cataloginventory_stock` (`stock_id`) ON DE)' in 
/www/lib/Zend/Db/Statement/Pdo.php:228
Stack trace: #0 /www/lib/Zend/Db/Statement/Pdo.php(228): 
PDOStatement->execute(Array) #1 
/www/lib/Varien/Db/Statement/Pdo/Mysql.php(110):
Zend_Db_Statement_Pdo->_execute(Array) #2 
/www/app/code/core/Zend/Db/Statement.php(291):
Varien_Db_Statement_Pdo_Mysql->_execute(Array) #3 
/www/lib/Zend/Db/Adapter/Abstract.php(479): 
Zend_Db_Statement->execute(Array) #4 
/www/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): 
Zend_Db_Adapter_Abstract->q in 
/www/lib/Zend/Db/Statement/Pdo.php on line 234

我通过堆栈溢出戳,但找不到任何适合'cataloginventory_stock_status'错误的东西。

I poked through stack overflow, but could not find anything suitable for the 'cataloginventory_stock_status'-error.

这可能是以前删除数据集时的一些剩余数据吗?

Could this be some leftover data from previous deletion of datasets?

您能澄清这个具体错误是什么吗?

Could you guys clearify what this specific error is about?

所有最好的

推荐答案

一些代码可能有帮助,但我想你在表 cataloginventory_stock_status 中插入一行,并且 stock_id 字段未填入或是不存在的值列 stock_id 上的表 cataloginventory_stock

Some code might help, but I think you are trying to insert a row in the table cataloginventory_stock_status and the stock_id field is not filled in or is a value that is not present in the table cataloginventory_stock on the column stock_id.

默认情况下,Magento在 cataloginventory_stock 表中的ID为 1 (我甚至不知道它的意思)。

By default Magento only has 1 row in the cataloginventory_stock table with id 1 (I don't even know what it means).

将此字段设置为1,也许可以工作。

Set that field to 1 and maybe it will work.

这篇关于Magento数据库错误:完整性约束违例:1452无法添加或更新子行:外键约束失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆