Magento2 Extension – How to Reinstall Properly

databaseextensionsinstallationmagento2

When using M1 i could reinstall the extension (launch setup/upgrade) just deleting the extension recording from the core_resource table. During the second magento address (or after cache refreshing) the extension executed all the files properly beginning from the 0 version.

Unfortunately i could not find the detailed information on how to reinstall the extension previously installed on my magento 2. Maybe somebody faced the same issue and knows the plan of actions for reinstalling the extension on magento 2 and could help. Your help will be highly appreciated.

EDIT

Example:

  1. I've got module v. 2.0.0 successfully installed with own tables
  2. I've delete the tables manually from the database
  3. I've got module v. 2.0.0 without tabels

How to reinstall tables without completely uninstalling and installing module?

UPDATE:

bin/magento module:uninstall <VendorName>_<ModuleName>
<VendorName>_<ModuleName> is not an installed composer package

where the <VendorName>_<ModuleName> – is the real vendor name and module name of the my module.

bin/magento module:status
List of enabled modules:
Magento_Store
.....
<VendorName>_<ModuleName>
.....
Magento_Weee
Magento_CatalogWidget
Magento_Wishlist
List of disabled modules:
None

UPDATE 2

My extension has the same name attribute value as in <VendorName> and <ModuleName>, in app/code/<VendorName>/<ModuleName>/etc/module.xml as it is indicated further:

<module name="<VendorName>_<ModuleName>" setup_version="1.0.0" />

In addition:

vagrant@magento-dev:/var/www/mgn2$ bin/magento module:disable <VendorName>_<ModuleName>
The following modules have been disabled:
- <VendorName>_<ModuleName>

Cache cleared successfully.
Generated classes cleared successfully. Please re-run Magento compile command
Info: Some modules might require static view files to be cleared. Use the optional --clear-static-content option to clear them.
vagrant@magento-dev:/var/www/mgn2$ bin/magento module:enable <VendorName>_<ModuleName>
The following modules have been enabled:
- <VendorName>_<ModuleName>

To make sure that the enabled modules are properly registered, run 'setup:upgrade'.
Cache cleared successfully.
Generated classes cleared successfully. Please re-run Magento compile command
Info: Some modules might require static view files to be cleared. Use the optional --clear-static-content option to clear them.

This bin/magento setup:upgrade goes without any errors.

UPDATE 2:
I’ve found the additional information. Maybe it will be useful for somebody.

mazhalai writes:

module:uninstall is intended to be used, only if you are absolutely
certain, that the module wont be used any longer. However, other
modules may have dependencies on the module that is to be removed.
Hence we use composer remove, which calculates dependencies and
removes code of the module from the file system. We cannot uninstall a
module that is NOT installed via composer
, since there is no way for
us to know about dependencies in such a situation. It is risky to
remove data and code in such a case. 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.

Link

PS: I am using the Magento 2.0.4

Best Answer

To run your extension again you need to remove your extension entry from setup_module table also remove your table which are created by your extension script then run below command

php bin/magento setup:upgrade

Thanks

Related Topic