Reading list Switch to dark mode

    Uninstaller in Magento 2

    Updated 15 March 2024

    Magento 2 allows uninstalling a module along with the data created during installation. You can create tables and attributes using InstallData and InstallSchema, and remove them with Magento’s Uninstaller script.

    The Uninstaller currently works for modules installed via Composer. It functions well with Magento v2.2.0, while earlier versions may have issues during uninstallation.

    For later versions, such as Magento v2.4*, you can directly uninstall a module using the uninstall command and remove data and tables using the Uninstall.php script found in Setup/Patch/Data.

    Refer to our Webkul Uninstall Module Attributes blog for a clearer understanding of removing installed data and tables from the database.

    First, we will install a TEST module using composer and then we will Uninstall it to check it is working.

    Searching for an experienced
    Magento 2 Company ?
    Find out More

    To install the sample module you need to include this module in your composer.json file. In composer.json file in require section add the following code.

    "webkul/uninstaller_test": "dev-master"

    Now, in repositories section in composer.json file add the following code.

    "type": "vcs",
    "url": "https://gitlab.com/ayazwebkul/Webkul_UninstallerTest.git"

    After adding the entry in composer.json,  run the following command

    php bin/magento composer install

    Now, your module is installed in vendor directory. Composer install just download the code from git.

    Now, you need to open the file Setup/Patch/Data/Uninstall.php and update the code according to the data you want to remove/delete permanently. After this, you need to run php bin/magento setup:upgrade for uninstallation of the data.

    In the module, we have created a table wk_test. Now, when we will run php bin/magento setup:upgrade and Uninstaller command all the data and the table along with the module will be removed.
    For Uninstalling the module, we need to run

    php bin/magento module:uninstall Webkul_UninstallerTest

    On successful Uninstall you will get the following message:

    Removing data of Webkul_UninstallerTest
    Removing Webkul_UninstallerTest from module registry in database
    Removing Webkul_UninstallerTest from module list in deployment configuration
    Removing code from Magento codebase:
    Cache cleared successfully.
    Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
    Info: Some modules might require static view files to be cleared. To do this, run 'module:uninstall' with the --clear-static-content option to clear them.
    Disabling maintenance mode

    Now, if you will check the database table wk_test created during module installation is removed. For more information regarding Uninstaller you can refer to Magento Doc.

    That’s all for this post, will be back with Uninstaller script removing the created attributes. If you have any query, please comment below.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home