0

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (marketplace.mg_nbmp_review, CONSTRAINT FK__nbmp_vendor FOREIGN KEY (vendor_id) REFERENCES ('marketplace/vendor') (vendor_id) ON DELETE CASCADE ON UPDATE CASCADE), query was: INSERT INTO mg_nbmp_review (vendor_id, vendor_name, customer_id, customer_name, customer_email, rating, review_comment, reviewed_date) VALUES (?, ?, ?, ?, ?, ?, ?, '2015-04-08 11:51:58')

<?php
$installer = $this;

$installer->startSetup();

$installer->run("


DROP TABLE IF EXISTS {$this->getTable('vendorreview/review')};
CREATE TABLE IF NOT EXISTS {$this->getTable('vendorreview/review')} (
    `review_id` INT(11) NOT NULL AUTO_INCREMENT,
    `vendor_id` INT(11) NOT NULL DEFAULT '0',
    `vendor_name` VARCHAR(1000) NOT NULL DEFAULT '0',
    `customer_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    `customer_name` VARCHAR(255) NOT NULL DEFAULT '0',
    `customer_email` VARCHAR(255) NOT NULL DEFAULT '0',
    `rating` ENUM('1','2','3','4','5') NOT NULL,
    `review_comment` VARCHAR(1000) NULL DEFAULT '0',
    `reply` VARCHAR(255) NULL DEFAULT '0',
    `status` INT(10) NOT NULL DEFAULT '0',
    `reviewed_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`review_id`),
    INDEX `FK__nbmp_vendor` (`vendor_id`),
    INDEX `FK__customer_entity` (`customer_id`),
    CONSTRAINT `FK__nbmp_vendor` FOREIGN KEY (`vendor_id`) REFERENCES {$this->getTable('marketplace/vendor')} (`vendor_id`) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT `FK__customer_entity` FOREIGN KEY (`customer_id`) REFERENCES {$this->getTable('customer/entity')} (`entity_id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COMMENT='Vendor Review Table'
ENGINE=InnoDB;
");

$installer->endSetup();

Where i m wrong?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
ND17
  • 210
  • 4
  • 21
  • similar Question answer is here [integrity-constraint-violation-1452-cannot-add-or-update-a-child-row](https://stackoverflow.com/questions/14063652/integrity-constraint-violation-1452-cannot-add-or-update-a-child-row) – Jasmeen Maradeeya Jul 25 '19 at 11:10

1 Answers1

1

First you should not drop table as describe above answer & this error shows that you are trying to insert a value to vendor_id which is not in its master table marketplace/vendor's vendor_id column value. It means Foreign key violation. you are inserting a wrong value which does not refers to any value in master table.

Hitesh Mundra
  • 1,538
  • 1
  • 9
  • 13