Question

I have created one module/extension using installer script in magento2.

After that I removed it, but tables in database still remain as it is.

can anyone tell me how to uninstall module/extension completely and remove extension's/module's tables from database?

Was it helpful?

Solution

If you install the module via composer, you can have create the Setup/Uninstall.php file that will be executed when running bin/magento module:uninstall -r [Namespace]_[Module].

The Uninstall.php file should look like this:

<?php

namespace Namespace\Module\Setup;

class Uninstall implements \Magento\Framework\Setup\UninstallInterface
{
    public function uninstall(
        \Magento\Framework\Setup\SchemaSetupInterface $setup,
        \Magento\Framework\Setup\ModuleContextInterface $context
    ) {
        if ($setup->tableExists('table_name_here')) {
            $setup->getConnection()->dropTable('table_name_here');
        }
    }
}

If you installed the module manually, you will need to cleanup your database manually also buy dropping the tables the module added.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top