Magento 2 : Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint...

What is the difference between rolling more dice versus fewer dice?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Saint abbreviation

How to not let the Identify spell spoil everything?

What will happen if I transfer large sums of money into my bank account from a pre-paid debit card or gift card?

Potential client has a problematic employee I can't work with

Explanation of a regular pattern only occuring for prime numbers

After checking in online, how do I know whether I need to go show my passport at airport check-in?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Play Zip, Zap, Zop

Why are all my replica super soldiers young adults or old teenagers?

What is the difference between "...", '...', $'...', and $"..." quotes?

How do you funnel food off a cutting board?

What is a DAG (Graph Theory)?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

Can you tell from a blurry photo if focus was too close or too far?

Limits of a density function

Why zero tolerance on nudity in space?

What is the wife of a henpecked husband called?

Why was Lupin comfortable with saying Voldemort's name?

Why do we have to make "peinlich" start with a capital letter and also end with -s in this sentence?

Why is Agricola named as such?

What makes papers publishable in top-tier journals?

How does one write from a minority culture? A question on cultural references



Magento 2 : Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails


I can't cancel orders. Integrity Constraint ViolationMagento Site Down with Integrity Constraint ViolationHow can I resolve Foreign Key constraint 'SQLSTATE[23000]: Integrity constraint violation: 1452Can't reindex Product Prices: a foreign key constraint failsTE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'Magento 2 Migration Integrity constraint violation Duplicate KeyHow to change save path of PDF files in magento 2Magento 2: How to override newsletter Subscriber modelSQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row?Foreign key constraint fails













0















When I save records, I got this error message.




SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (report.vendorname_modulename_entity, CONSTRAINT VENDORNAME_MODULENAME_ENTT_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID FOREIGN KEY (entity_type_id) REFERENCES eav_entity_type (entity_type_id) ), query was: INSERT INTO vendorname_modulename_entity (created_at, updated_at) VALUES ('2019-02-26 00:00:00', '2019-02-27 05:12:31')




Save controller file (execute function):



$storeId = (int) $this->getRequest()->getParam('store_id', 0);
$data = $this->getRequest()->getParams();

/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($data) {
$params = [];
$model = $this->modelFactory->create();
$params['store'] = $storeId;
if (empty($data['entity_id'])) {
$data['entity_id'] = null;
} else {
$model->load($data['entity_id']);
$params['entity_id'] = $data['entity_id'];
}
$model->setData('entity_type_id', 10);
$model->setData('attribute_set_id', 17);
$model->setData('store_id', $storeId);
$model->setData('field_title', $data['field_title']);
$model->setData('field_url', $data['field_url']);
$model->setData('field_desc', $data['field_desc']);
$model->setData('created_at', $this->_dateFactory->create()->date());
$model->setData('updated_at', $this->_dateFactory->create()->date());

try {
$model->save();
$this->messageManager->addSuccessMessage(__('You saved this record.'));
$this->_getSession()->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$params['entity_id'] = $model->getId();
$params['_current'] = true;
return $resultRedirect->setPath('*/*/edit', $params);
}
return $resultRedirect->setPath('*/*/');
} catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.'));
}

$this->_getSession()->setFormData($this->getRequest()->getPostValue());
return $resultRedirect->setPath('*/*/edit', $params);
}
return $resultRedirect->setPath('*/*/');


How I solve this error?









share



























    0















    When I save records, I got this error message.




    SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (report.vendorname_modulename_entity, CONSTRAINT VENDORNAME_MODULENAME_ENTT_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID FOREIGN KEY (entity_type_id) REFERENCES eav_entity_type (entity_type_id) ), query was: INSERT INTO vendorname_modulename_entity (created_at, updated_at) VALUES ('2019-02-26 00:00:00', '2019-02-27 05:12:31')




    Save controller file (execute function):



    $storeId = (int) $this->getRequest()->getParam('store_id', 0);
    $data = $this->getRequest()->getParams();

    /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
    $resultRedirect = $this->resultRedirectFactory->create();
    if ($data) {
    $params = [];
    $model = $this->modelFactory->create();
    $params['store'] = $storeId;
    if (empty($data['entity_id'])) {
    $data['entity_id'] = null;
    } else {
    $model->load($data['entity_id']);
    $params['entity_id'] = $data['entity_id'];
    }
    $model->setData('entity_type_id', 10);
    $model->setData('attribute_set_id', 17);
    $model->setData('store_id', $storeId);
    $model->setData('field_title', $data['field_title']);
    $model->setData('field_url', $data['field_url']);
    $model->setData('field_desc', $data['field_desc']);
    $model->setData('created_at', $this->_dateFactory->create()->date());
    $model->setData('updated_at', $this->_dateFactory->create()->date());

    try {
    $model->save();
    $this->messageManager->addSuccessMessage(__('You saved this record.'));
    $this->_getSession()->setFormData(false);
    if ($this->getRequest()->getParam('back')) {
    $params['entity_id'] = $model->getId();
    $params['_current'] = true;
    return $resultRedirect->setPath('*/*/edit', $params);
    }
    return $resultRedirect->setPath('*/*/');
    } catch (Exception $e) {
    $this->messageManager->addErrorMessage($e->getMessage());
    $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.'));
    }

    $this->_getSession()->setFormData($this->getRequest()->getPostValue());
    return $resultRedirect->setPath('*/*/edit', $params);
    }
    return $resultRedirect->setPath('*/*/');


    How I solve this error?









    share

























      0












      0








      0








      When I save records, I got this error message.




      SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (report.vendorname_modulename_entity, CONSTRAINT VENDORNAME_MODULENAME_ENTT_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID FOREIGN KEY (entity_type_id) REFERENCES eav_entity_type (entity_type_id) ), query was: INSERT INTO vendorname_modulename_entity (created_at, updated_at) VALUES ('2019-02-26 00:00:00', '2019-02-27 05:12:31')




      Save controller file (execute function):



      $storeId = (int) $this->getRequest()->getParam('store_id', 0);
      $data = $this->getRequest()->getParams();

      /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
      $resultRedirect = $this->resultRedirectFactory->create();
      if ($data) {
      $params = [];
      $model = $this->modelFactory->create();
      $params['store'] = $storeId;
      if (empty($data['entity_id'])) {
      $data['entity_id'] = null;
      } else {
      $model->load($data['entity_id']);
      $params['entity_id'] = $data['entity_id'];
      }
      $model->setData('entity_type_id', 10);
      $model->setData('attribute_set_id', 17);
      $model->setData('store_id', $storeId);
      $model->setData('field_title', $data['field_title']);
      $model->setData('field_url', $data['field_url']);
      $model->setData('field_desc', $data['field_desc']);
      $model->setData('created_at', $this->_dateFactory->create()->date());
      $model->setData('updated_at', $this->_dateFactory->create()->date());

      try {
      $model->save();
      $this->messageManager->addSuccessMessage(__('You saved this record.'));
      $this->_getSession()->setFormData(false);
      if ($this->getRequest()->getParam('back')) {
      $params['entity_id'] = $model->getId();
      $params['_current'] = true;
      return $resultRedirect->setPath('*/*/edit', $params);
      }
      return $resultRedirect->setPath('*/*/');
      } catch (Exception $e) {
      $this->messageManager->addErrorMessage($e->getMessage());
      $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.'));
      }

      $this->_getSession()->setFormData($this->getRequest()->getPostValue());
      return $resultRedirect->setPath('*/*/edit', $params);
      }
      return $resultRedirect->setPath('*/*/');


      How I solve this error?









      share














      When I save records, I got this error message.




      SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (report.vendorname_modulename_entity, CONSTRAINT VENDORNAME_MODULENAME_ENTT_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID FOREIGN KEY (entity_type_id) REFERENCES eav_entity_type (entity_type_id) ), query was: INSERT INTO vendorname_modulename_entity (created_at, updated_at) VALUES ('2019-02-26 00:00:00', '2019-02-27 05:12:31')




      Save controller file (execute function):



      $storeId = (int) $this->getRequest()->getParam('store_id', 0);
      $data = $this->getRequest()->getParams();

      /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
      $resultRedirect = $this->resultRedirectFactory->create();
      if ($data) {
      $params = [];
      $model = $this->modelFactory->create();
      $params['store'] = $storeId;
      if (empty($data['entity_id'])) {
      $data['entity_id'] = null;
      } else {
      $model->load($data['entity_id']);
      $params['entity_id'] = $data['entity_id'];
      }
      $model->setData('entity_type_id', 10);
      $model->setData('attribute_set_id', 17);
      $model->setData('store_id', $storeId);
      $model->setData('field_title', $data['field_title']);
      $model->setData('field_url', $data['field_url']);
      $model->setData('field_desc', $data['field_desc']);
      $model->setData('created_at', $this->_dateFactory->create()->date());
      $model->setData('updated_at', $this->_dateFactory->create()->date());

      try {
      $model->save();
      $this->messageManager->addSuccessMessage(__('You saved this record.'));
      $this->_getSession()->setFormData(false);
      if ($this->getRequest()->getParam('back')) {
      $params['entity_id'] = $model->getId();
      $params['_current'] = true;
      return $resultRedirect->setPath('*/*/edit', $params);
      }
      return $resultRedirect->setPath('*/*/');
      } catch (Exception $e) {
      $this->messageManager->addErrorMessage($e->getMessage());
      $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.'));
      }

      $this->_getSession()->setFormData($this->getRequest()->getPostValue());
      return $resultRedirect->setPath('*/*/edit', $params);
      }
      return $resultRedirect->setPath('*/*/');


      How I solve this error?







      magento2 error





      share












      share










      share



      share










      asked 3 mins ago









      DenishDenish

      817




      817






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263579%2fmagento-2-integrity-constraint-violation-1452-cannot-add-or-update-a-child-ro%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263579%2fmagento-2-integrity-constraint-violation-1452-cannot-add-or-update-a-child-ro%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          夢乃愛華...