Magento2 Module Database Upgrade – MySQL Error and Possible Duplicates Running bin/magento setup:upgrade

databasemagento2moduleupgrade

I've renamed a custom module from MagicPack_magicheader to MagicPack_Magicheader and trying to now update by running setup:upgrade. I get the following error:

  [Zend_Db_Statement_Exception]                                                                                                                                                                      
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'MagicPack_Magicheader' for key 'PRIMARY', query was: INSERT INTO `setup_module` (`module`, `schema_version`) VALUES (?, ?)  



  [PDOException]                                                                                                   
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'MagicPack_Magicheader' for key 'PRIMARY'  

On the site itself, it tells me to run upgrade, but I've noticed two entries:

The following modules are outdated:
MagicPack_Magicheader schema: current version - none, required version - 0.2.0
MagicPack_Magicheader data: current version - none, required version - 0.2.0

This seems to match the issue with duplicate entries. Can anyone let me know why there are duplicate entries, one for schema and one for data? The module.xml file is as follows:

<?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="MagicPack_Magicheader" setup_version="0.0.1"/>
</config>

Thanks

Best Answer

It is easy to fix, follow the instructions.

  1. Find setup_module table name in the database.

  2. Then, find the row which contains the name of your module in setup_module table (In your case, module_name is MagicPack_Magicheader) and delete this row (when you run setup:upgrade it will be automatically re-generate)

    DELETE FROM setup_module where module = 'Module_Name'
    
  3. Then, run the command bin/magento setup:upgrade

Reason: Your old module information already exists, so whenever you run setup upgrade, it is throwing Duplicate entry error. After removing old module information its successfully get upgrade.

have good luck.

Related Topic