Magento – Magento 2 module version number not editable

configurationerrormagento2module

I have just started exploring Magento 2 structure and code-flow, also module development.

When I created module from an online module generator and tried to change it's "setup_version" & "schema_version" in "module.xml" (doesn't matter if I increase or decrease version, it should be changeable as needed, I guess) and then if I follow all processes of compiling and enabling the module after flushing caches, it generates error as below on running the website:

a:4:{i:0;s:279:"Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory. 
The following modules are outdated:
Company1_Module1 schema: current version - 2.0.0, required version - 1.0.0
Company1_Module1 data: current version - 2.0.0, required version - 1.0.0";i:1;s:3447:"#0 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))

Below is my module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
  <module name="Company1_Module1" schema_version="1.0.0" setup_version="1.0.0" data_version="1.0.0"/>
</config>

I know "data_version" is not needed but I did it for trial and error checks, still it gives error as above.

Need urgent assistance and guidance.

Best Answer

  1. Only setup_version is required. schema_version and data_version is obsolete.
  2. Right now magento2 does not support downgrading. You have current version - 2.0.0 which is the version of the module in the setup_module table, and you are attempting to downgrade to 1.0.0. This is not supported. Please update this record in the database directly, or uninstall module using bin/magento module:uninstall Company1_Module1 and then reinstall and enable via bin/magento module:enable. Of course, you will have to run compile, and regenerate static files etc.