Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:10:59+00:00 2026-05-28T13:10:59+00:00

I have the YAML for the invoice data to go into the testing database:

  • 0

I have the YAML for the invoice data to go into the testing database:

After The Scope data for the website, the Customer Data, Product Data, and Order Data, there is the Invoice Data, and I will only paste that bit.

Everything works fine in terms of the data setup, up to inserting the invoice data, when i remove the Invoice Items Data. Once I add the Invoice Items Data, it gives me the following error in the SQL Execution, which cannot be right, as the data was valid when I exported it from MySQL to YAML.

Error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`xxxx_unit_tests`.`sales_flat_invoice_item`, CONSTRAINT `FK_SALES_FLAT_INVOICE_ITEM_PARENT` FOREIGN KEY (`parent_id`) REFERENCES `sales_flat_invoice` (`entity_id`) ON DELETE CASCADE ON UPDATE)

I checked the invoice data again, to ensure everything is correct, and saw that the second record was there, and not the first one, but there was no errors thrown when creating the invoice data, and thus the reason for the previous error, as there was no invoice with entity_id of 1.

I need to know why the second row was showing up, and not the first data set, with entity_id of 1 for invoices.

Has anyone else come across this issue? when I leave in just one invoice data set, and one invoice Item data set, then it works.

tables:
  sales/invoice:
    - entity_id: 1
      store_id: 99
      base_grand_total: 20.0000
      shipping_tax_amount: 0.0000
      tax_amount: 0.0000
      base_tax_amount: 0.0000
      store_to_order_rate: 1.0000
      base_shipping_tax_amount: 0.0000
      base_discount_amount: 0.0000
      base_to_order_rate: 1.0000
      grand_total: 20.0000
      shipping_amount: 0.0000
      subtotal_incl_tax: 20.0000
      base_subtotal_incl_tax: 20.0000
      store_to_base_rate: 1.0000
      base_shipping_amount: 0.0000
      total_qty: 1.0000
      base_to_global_rate: 1.0000
      subtotal: 20.0000
      base_subtotal: 20.0000
      discount_amount: 0.0000
      billing_address_id: 1
      order_id: 1
      state: 1
      store_currency_code: "USD"
      order_currency_code: "USD"
      base_currency_code: "USD"
      global_currency_code: "USD"
      increment_id: 200009925
      created_at: "2012-01-19 23:40:27"
      updated_at: "2012-01-19 23:40:27"
      hidden_tax_amount: 0.0000
      base_hidden_tax_amount: 0.0000

    - entity_id: 2
      store_id: 99
      base_grand_total: 20.0000
      shipping_tax_amount: 0.0000
      tax_amount: 0.0000
      base_tax_amount: 0.0000
      store_to_order_rate: 1.0000
      base_shipping_tax_amount: 0.0000
      base_discount_amount: 0.0000
      base_to_order_rate: 1.0000
      grand_total: 20.0000
      shipping_amount: 0.0000
      subtotal_incl_tax: 20.0000
      base_subtotal_incl_tax: 20.0000
      store_to_base_rate: 1.0000
      base_shipping_amount: 0.0000
      total_qty: 1.0000
      base_to_global_rate: 1.0000
      subtotal: 20.0000
      base_subtotal: 20.0000
      discount_amount: 0.0000
      billing_address_id: 1
      order_id: 2
      state: 2
      store_currency_code: "USD"
      order_currency_code: "USD"
      base_currency_code: "USD"
      global_currency_code: "USD"
      increment_id: 200009925
      created_at: "2012-01-19 23:40:27"
      updated_at: "2012-01-19 23:40:27"
      hidden_tax_amount: 0.0000
      base_hidden_tax_amount: 0.0000

  sales/invoice_item:
    - entity_id: 1
      parent_id: 1
      base_price: 20.0000
      base_weee_tax_row_disposition: 0.0000
      weee_tax_applied_row_amount: 0.0000
      base_weee_tax_applied_amount: 0.0000
      base_row_total: 20.0000
      row_total: 20.0000
      weee_tax_row_disposition: 0.0000
      base_weee_tax_disposition: 0.0000
      price_incl_tax: 20.0000
      weee_tax_applied_amount: 0.0000
      base_price_incl_tax: 20.0000
      qty: 1.0000
      weee_tax_disposition: 0.0000
      base_weee_tax_applied_row_amount: 0.0000
      price: 20.0000
      base_row_total_incl_tax: 20.0000
      row_total_incl_tax: 20.0000
      product_id: 1
      order_item_id: 1
      weee_tax_applied: "a:0:{}"
      sku: "gift"
      name: "Test Giftcard"

    - entity_id: 2
      parent_id: 2
      base_price: 20.0000
      base_weee_tax_row_disposition: 0.0000
      weee_tax_applied_row_amount: 0.0000
      base_weee_tax_applied_amount: 0.0000
      base_row_total: 20.0000
      row_total: 20.0000
      weee_tax_row_disposition: 0.0000
      base_weee_tax_disposition: 0.0000
      price_incl_tax: 20.0000
      weee_tax_applied_amount: 0.0000
      base_price_incl_tax: 20.0000
      qty: 1.0000
      weee_tax_disposition: 0.0000
      base_weee_tax_applied_row_amount: 0.0000
      price: 20.0000
      base_row_total_incl_tax: 20.0000
      row_total_incl_tax: 20.0000
      product_id: 1
      order_item_id: 2
      weee_tax_applied: "a:0:{}"
      sku: "gift"
      name: "Test Giftcard"

I have run out of ideas, as to what is causing this issue

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:11:00+00:00Added an answer on May 28, 2026 at 1:11 pm

    Found out what the issue was.

    It was caused by one thing, but the error indicated something else. A nasty gotcha.

    The problem child was the second invoice, having the same increment_id.
    When the data gets added tot he test database, it does an insert/update_on_duplicate statement, which did something completely weird.

    try {
        $this->_getWriteAdapter()->insertOnDuplicate(
             $this->getTable($tableEntity),
             $records
        );
    } catch (Exception $e) {
        throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
            sprintf('Unable to insert/update records for a table "%s"', $tableEntity), 
            $e
        );
    }
    

    The first invoice got inserted without any issues, and when it came to the point of inserting the second invoice, it realized the increment_id field, which has a Unique index on it, is the same as on the first invoice, and then used the data from the second invoice, and updated the first inserted record with that data.

    The second invoice had an entity_id of “2”, so that then became the entity_id of the first inserted record, and made it look like only the second invoice data was inserted, and not the first invoice data.

    When it got to the point where the Invoice Items was being inserted, the “Integrity constraint violation” error got flagged behind the scenes, where I traced it down to, as there was no Invoice with entity_id of “1” in the database, to link the child item to, as its parent’s entity_id was updated to “2”.

    Maybe the “Update on duplicate” part of the insert, should be switched off, when you know that you are not going to update data, in the test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have correct order of values inside Ruby array after parsing YAML
I have YAML data that looks sort of like this, but ~150k of it:
Hi i have a yaml file like so --- data: - date: 2004-06-11 description:
I have a command line app the continuously outputs YAML data in the form:
I'm using rails to build a website. I have a yaml file contails some
I want to import data with YAML. I have a model named Question package
In the following Ruby example, is there a mode to have YAML NOT silently
I have a YAML file of groups that I would like to get into
I have written my yaml schema for the database for my Symfony+doctrine application, and
Is there a way to have uninterpreted strings within a YAML file? My goal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.