1

I'm trying to delete some data from database with direct sql query, but I get a Cardinality violation.

$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "DELETE * FROM catalog_product_super_link WHERE parent_id =" . 
$_product->getId() . "AND product_id = ". $child_id . ";";
$conn->query($sql);

And the full error is:

SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s), query was: SELECT `catalog_product_entity`.* FROM `catalog_product_entity` WHERE (entity_id ='1', '3', '4', '5', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442')

I'm not very good with sql queries... so I need a bit of help here

edit: catalog_product_super_link table

link_id  -  product_id  -  parent_id
1           1              2
2           3              2
3           4              2
4           5              2
5           6              7
6           8              7
7           9              7
8           10             7
9           11             7
10          12             7
11          13             7
15599       13             7182
12          14             7
15600       14             7182
13          15             7
14          16             7
15          17             7
16          18             7
17          19             7
18          20             7
19          21             7
20          22             7
21          23             24
22          25             24
23          26             24
24          27             24
25          28             24
26          29             24
27          30             24
...         ...            ...
2
  • can you please update your post with catalog_product_super_link table data? Nov 23, 2017 at 15:42
  • I update with a part of the table data, it's a bit long (15604 rows).
    – Alex
    Nov 23, 2017 at 15:53

2 Answers 2

1

Try this code. I've make some changes in query.

$sql = "DELETE * FROM catalog_product_super_link WHERE parent_id = " . (int)$_product->getId() . "AND product_id = " . (int)$child_id;
4
  • same result of cardinality violation
    – Alex
    Nov 23, 2017 at 16:03
  • did you check that you are getting correct ID in $_product->getId() and $child_id Nov 23, 2017 at 16:04
  • Your answer was near the solution, I've just checked the values that I was passing to the query, and one of them was not an int. So it failed. Once I corrected the value it is working fine.
    – Alex
    Nov 23, 2017 at 16:23
  • Glad to know that its working fine. Please mark it as resolved Nov 23, 2017 at 16:23
0
$sql = "SET FOREIGN_KEY_CHECKS=0; DELETE * FROM catalog_product_super_link WHERE parent_id = " . (int)$_product->getId() . " AND product_id = " . (int)$child_id."; SET FOREIGN_KEY_CHECKS=1;";

the query is correct but the query cannot find product with id 7 for example you must disable FOREIGN_KEY_CHECKS before execute query test my query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.