3

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

1

1 Answer 1

17

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.

3
  • welcome @MichaelWatson Apr 23, 2016 at 12:04
  • This is incomplete - what do you do when you find 'setup_module'? Aug 1, 2017 at 19:07
  • I don't even have setup_module table in Magento DB. My store is running Magento 2.4.2. Would the table have changed in this version? May 16, 2022 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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