【问题标题】:Magento DB Error: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsMagento DB 错误:违反完整性约束:1452 无法添加或更新子行:外键约束失败
【发布时间】:2014-03-25 14:22:07
【问题描述】:

现在我正在为 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】:

    某些代码可能会有所帮助,但我认为您正试图在表 cataloginventory_stock_status 中插入一行,而 stock_id 字段未填写或者是表 cataloginventory_stock 中不存在的值专栏stock_id

    默认情况下,Magento 在 cataloginventory_stock 表中只有 1 行,id 为 1(我什至不知道这意味着什么)。

    将该字段设置为 1,也许它会起作用。

    【讨论】:

    • 是的,你是对的!非常感谢!这成功了:-) mysql_query('INSERT INTO cataloginventory_stock SET stock_name = \'Default\';');
    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 2018-04-26
    • 2020-08-13
    • 1970-01-01
    • 2016-10-27
    • 2018-02-12
    相关资源
    最近更新 更多