4

I am creating an module in Magento 2 ( ver. 2.0.0). I have registered my module in app/etc/config.xml

'Namespace_Modulename => 1,

My module.xml file under app/code/Namespace/Modulename/etc/module.xml

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="Namespace_Modulename" setup_version="2.0.1"/> 
</config>

When I run my module Magento 2 generate below error :

Setup version for module 'Namespace_Modulename' is not specified

My module was working fine before stable release, after upgraded to stable release I start getting this error. I searched lot on google before adding here, got some results but none of then working for me.

Kindly guide me where I am doing wrong.

  • i guess setup_version is magento version, not module version. Try 2.0.0 – MeenakshiSundaram R Nov 23 '15 at 7:01
  • Thanks for reply, I just replaced the setup_version with 2.0.0 but still getting the same error – Deepak Mankotia Nov 23 '15 at 7:04
  • I have one more query, if setup_verion is magento version then where we specify module version? – Deepak Mankotia Nov 23 '15 at 7:05
  • 1
    as far as i'm aware setup_version="1.0.0" is the module version – rob3000 Nov 23 '15 at 7:11
8

You will also need to create a registration.php file to register your module:

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Namespace_Modulename',
    __DIR__
);

In app/code/Namespace/Modulename/registration.php.

Also you shouldn't need to manually change app/etc/config.xml after you have created a app/code/Namespace/Modulename/moudle.xml and registration.php running bin/magento module:enable Namespace_Modulename will update this for you.

A good blog here for the full process https://www.ashsmith.io/magento2/module-from-scratch-module-part-1-setup/

  • Thanks this is very helpful for me, this resolve my issue – Deepak Mankotia Nov 23 '15 at 7:15
  • Now I am getting another error : Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory. The following modules are outdated: Namespace_Modulename schema: current version - none, required version - 1.0.0 Namespace_Modulename data: current version - none, required version - 1.0.0 – Deepak Mankotia Nov 23 '15 at 7:15
  • have you then tried running bin/magento setup:upgrade ? – rob3000 Nov 23 '15 at 7:27
  • When i run this command in terminal I got : [InvalidArgumentException] There are no commands defined in the "setup" namespace. – Deepak Mankotia Nov 23 '15 at 7:28
  • 1
    try updating your namespaceSchema in your module.xml to xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd" – rob3000 Nov 23 '15 at 7:33
1

Try this in module.xml: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Namespace_Modulename" schema_version="2.0.1" setup_version="2.0.1"/> </config> Add registration.php and composer.json in your module.

/app/code/Namespace/Module/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Namespace_Module',
    __DIR__
);

/app/code/Namespace/Module/composer.json

{
    "name": "namespace/module",
    "description": "namespace",
    "require": {
      "php": "~5.5.0|~5.6.0|~7.0.0",
      "magento/framework": "100.0.*",
      "magento/module-ui": "100.0.*",
      "magento/module-config": "100.0.*",
      "magento/module-contact": "100.0.*"    
    },
    "type": "magento2-module",
    "version": "100.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "extra": {
        "map": [
            [
                "*",
                "Namespace/Module"
            ]
        ]
    },
    "autoload": {
        "files": [ "registration.php" ],
        "psr-4": {
            "namespace\\module\\": ""
        }
    }
}

Now run magento setup:upgrade and schema upgrade if applicable.

Now clear all caches and var/generation folder. Login to admin panel > Stores > Configuration > Advanced > Advanced. Your module should be listed here now.

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