I've create an install schema for a custom module. The problem is, that I put a field as foreign key but later it turned out I connected it to the wrong foreign field and table.

I've made the correct changes to the InstallSchema file and i want to run it again, but as iunderstand, the InstallSchema file only runs once. What is the best way to act in this situation ?

  • try by deleting it from setup_module table & it's table name. It is same as is equivalent of core_resource in Magento 1.
    – Arjun
    Jul 14, 2016 at 12:46
  • you can use UpgradeSchema.php
    – Keyur Shah
    Jul 14, 2016 at 12:46
  • Arjun, thank you, this was exactly what I was looking for, no UpdateSchema, nothing, just changed 2 rows in the installSchema, removed that row form the table you mentioned, runned setup:upgrade again and it worked, 10x a lot. Jul 14, 2016 at 13:51

1 Answer 1


If you want to update existing table/schema adding/updating row then,

Step 1: Create UpgradeSchema.php under Setup folder. Get Idea from following code.

namespace Vendor\ModuleName\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class UpgradeSchema implements  UpgradeSchemaInterface
    public function upgrade(SchemaSetupInterface $setup,
                            ModuleContextInterface $context){
        if (version_compare($context->getVersion(), '1.0.1') < 0) 

Step 2: Change the setup_version value in module.xml

Step 3: Run php bin/magento setup:upgrade command from CLI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.