注意:这是Magento Catalog Search Query Explanation
的后续行动对于此查询:
INSERT INTO `catalogsearch_result`
(
SELECT
'0',
`s`.`product_id`,
-(
( MATCH(`s`.`data_index`) AGAINST ('ip335') ) +
( 5 * ( MATCH(`s`.`data_index_1`) AGAINST('ip335') ) ) +
( 3 * ( MATCH(`s`.`data_index_2`) AGAINST('ip335') ) ) +
( 2 * ( MATCH(`s`.`data_index_3`) AGAINST ('ip335') ) )
)
FROM `mikkelrickycatalogsearch_fulltext` AS `s`
INNER JOIN `catalog_product_entity` AS `e`
ON `e`.`entity_id`=`s`.`product_id`
WHERE
(
(`s`.`data_index` LIKE '%ip335%')
)
AND `s`.`store_id`='2'
)
ON DUPLICATE
KEY UPDATE `relevance` = VALUES(`relevance`);
我收到以下错误:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
(`magento_1_4`.`catalogsearch_result`, CONSTRAINT `FK_CATALOGSEARCH_RESULT_QUERY` FOREIGN KEY
(`query_id`) REFERENCES `catalogsearch_query` (`query_id`) ON DELETE CASCADE ON UPDATE CASCADE)
问题是:为什么? :)
在这种情况下,如果我只是将子查询作为SELECT语句运行,我会得到几个结果(因此找到了给定条件的产品)。但是,catalogsearch_result
上没有任何匹配产品的条目,这会导致上述查询执行INSERT
。鉴于此,为什么会抛出约束错误? catalogsearch_query
首先需要包含匹配query_id
记录的行吗?