10

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?

1 Answer 1

11

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.

3
  • I have installed module manually
    – Surya
    Jul 11, 2016 at 6:36
  • Then you have to cleanup yourself the database.
    – Marius
    Jul 11, 2016 at 6:43
  • 1
    I have this same issue. i have removed tables manually but i can't reinstall it using installer script.
    – HiMs
    Jul 11, 2016 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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