Skip to main content

Posts

Showing posts with the label SQL

What startSetup() and endSetup() methods actually does?

The startSetup() and endSetup() methods are used in setup scripts. They are often at the beginning and the end of an upgrade/install method, like in “upgrade()” method of Magento/Catalog/Setup/UpgradeData.php The question is “do you really need them?” Or does it just “look necessary”? This blog post explores what these functions do and then explains when you do and do not need to use these methods. Let’s see what these methods are doing. First, startSetup(): public function startSetup() {   $this->rawQuery("SET SQL_MODE=''");  $this->rawQuery("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");   $this->rawQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");   return $this;  } 1. Disable foreign keys check. It may be necessary in some rare cases (for example, in a case of cyclic references between tables), but it’s not needed in common situations. It even may lead to hiding real problems