Can I delete the table from the Magento database when the module is disabled and uninstalled? Because the table was created when the module is installed.

1 Answer 1


You can use the UninstallInterface of your module to drop the tables during uninstall process:



namespace Vendor\Module\Setup;

use Magento\Framework\Setup\UninstallInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class Uninstall implements UninstallInterface
     * Module uninstall code
     * @param SchemaSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
    public function uninstall(
        SchemaSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $connection = $setup->getConnection();

But this script works only when module has been installed using the Composer:

Hence, it is recommended that for modules NOT installed via composer, manual clean up of the database and filesystem is necessary. In module enable/disable, the code is never removed from the filesystem, so that it can be used if required at a later time. Hence, it is not removed from the setup_module table.

(additional information here).


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.