Magento DB错误:完整性约束违规:1452无法添加或更新子行:外键约束失败

问题描述 投票:0回答:1

现在我正在为Magento产品,类别和属性集编写自定义导出文件。我知道使用裸MySQL和PHP是不好的做法,但这就是目前的方式。

使用我的自定义函数创建产品时,第一个产品上会出现此错误:

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'错误的东西。

这可能是之前删除数据集的剩余数据吗?

你能澄清一下这个具体的错误是什么吗?

mysql magento import foreign-keys constraints
1个回答
3
投票

一些代码可能会有所帮助,但我认为您试图在表cataloginventory_stock_status中插入一行并且未填充stock_id字段,或者是cataloginventory_stock列中stock_id表中不存在的值。

默认情况下,Magento在cataloginventory_stock表中只有1行,id为1(我甚至不知道它的含义)。

将该字段设置为1,它可能会起作用。

© www.soinside.com 2019 - 2024. All rights reserved.