Unable to load Fixtures couse of foreign key constraint fails EComDev PHPUnit
-
23-01-2021 - |
Domanda
i want to add a complete order in my Test by a fixture.
The file looks like that:
eav:
#==================================================
# Customers
#==================================================
customer:
-
entity_id: 1238299
entity_type_id: 1
attribute_set_id: 0
website_id: 1
default_billing: 2606480
default_shipping: 2606480
otherData
otherData
tables:
#==================================================
# Orders
#==================================================
sales/order:
entity_id: 2842007
store_id: 1
customer_id: 1238299
billing_address_id: 6269997
quote_address_id: ~
quote_id: 21682178
shipping_address_id: 6269998
increment_id: 102468857
otherData
otherData
#==================================================
# Adresses
#==================================================
sales/order_address:
- entity_id: 6269998
parent_id: 2842007
customer_address_id:
quote_address_id:
otherData
otherData
- entity_id: 6269997
parent_id: 2842007
customer_address_id: 2606480
quote_address_id:
otherData
otherData
#=====================================
# Order items
#=====================================
sales/order_item:
-
item_id: 5033860
order_id: 2842007
otherData
otherData
-
item_id: 5033861
order_id: 2842007
parent_item_id: ~
otherData
otherData
#===================================
# Payments
#===================================
sales/order_payment:
-
entity_id: 3701517
parent_id: 2842007
#===================================
# Quots
#===================================
sales/quote:
When i know start the test and load this fixture i become this error:
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 (
unit_test
.sales_flat_order_address
, CONSTRAINTFK_SALES_FLAT_ORDER_ADDRESS_PARENT_ID_SALES_FLAT_ORDER_ENTITY_ID
FOREIGN KEY (parent_id
) REFERENCESsales_flat_order
(entity_id
) ON D)' in /Users/xxx/workspace/magento_shop/vendor/xxx/ext.magento.ecomdev.phpunit/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php on line 78PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
unit_test
.sales_flat_order_address
, CONSTRAINTFK_SALES_FLAT_ORDER_ADDRESS_PARENT_ID_SALES_FLAT_ORDER_ENTITY_ID
FOREIGN KEY (parent_id
) REFERENCESsales_flat_order
(entity_id
) ON D) in /Users/xxx/workspace/magento_shop/www/lib/Zend/Db/Statement/Pdo.php on line 228
Did i have to load them in another order, or is something missing? Maybe is there a way to deactivate foreign key constraint?
Best Regards
Soluzione
So, wow... After some hours of debugging the wrong thing i found out that the sales/order has to be an array like this:
sales/order: - entity_id: 2842007 store_id: 1 customer_id: 1238299 billing_address_id: 6269997 quote_address_id: ~ quote_id: 21682178 shipping_address_id: 6269998 increment_id: 102468857 otherData otherData
after that it inserts the order the right way and not only with null values and then i can perfectly add the addresses in fact that the entity_id of order is valid.