Fixed Importer: Duplicate entry because of the example category


Well-known member
No major thing, but the impporter throws a "Duplicate entry '1' for key 'PRIMARY'" during importing the categories.

It does so because of the "Example Category". All other importers either delete the existing thing or ignore the error.
Mysqli statement execute error : Duplicate entry '1' for key 'PRIMARY'

    Zend_Db_Statement_Mysqli->_execute() in Zend/Db/Statement.php at line 297
    Zend_Db_Statement->execute() in Zend/Db/Adapter/Abstract.php at line 479
    Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 574
    Zend_Db_Adapter_Abstract->insert() in XenForo/DataWriter.php at line 1624
    XenForo_DataWriter->_insert() in XenForo/DataWriter.php at line 1613
    XenForo_DataWriter->_save() in XenForo/DataWriter.php at line 1405
    XenForo_DataWriter->save() in XenGallery/Model/Importers.php at line 96
    XenGallery_Model_Importers->importCategory() in XenGallery/Importer/PhotopostVb.php at line 552
    XenGallery_Importer_PhotopostVb->_importCategory() in XenGallery/Importer/PhotopostVb.php at line 459
    XenGallery_Importer_PhotopostVb->stepCategories() in XenForo/Importer/Abstract.php at line 97
    XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 187
    XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 239
    XenForo_ControllerAdmin_Import->_startStep() in XenForo/ControllerAdmin/Import.php at line 182
    XenForo_ControllerAdmin_Import->actionStartStep() in XenForo/FrontController.php at line 347
    XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
    XenForo_FrontController->run() in /home/forumname/public_html/eos/admin.php at line 13

Chris D

XenForo developer
Staff member
I was originally going to mark this As Designed because, basically, it is... but I will give it some thoughts about the merits of silencing the error or taking action against the category.

I mostly wouldn't want to delete the Example Category because it is not uncommon for people to want to do double imports into the Gallery, e.g. from PhotoPost Pro and from vBulletin Albums. It would be quite easy for someone to select "Retain content IDs" on the second almost on auto pilot and if they've already done an import that already contains a category with the ID of 1 then that could cause problems in itself.

Silently ignoring would also cause confusion when they can no longer find the category after the import. They wouldn't be expecting their imported media to be in the default category under the name of Example Category if that category was named something else before the import.

It's also worth noting that the default importer can throw duplicate key errors too if other items besides the default nodes exist. So the default importer would delete node 1 and node 2 if retain keys is selected but if you have created other nodes and that node existed in the source data then you would get a duplicate key error.

So I'm still steering towards As Designed on this one but I'll give it some more thought :)


Well-known member
All I want is a consistent behaviour.

During dozens of Xenforo imports I have learned that default categories/forums are overwritten. Why should this importer behave different?

Chris D

XenForo developer
Staff member
For the reasons already stated, it wasn't going to be sufficient to make it behave exactly the same as default importers, however in the next release we have made some changes.

If the option to retain keys is set then we do two checks. Is there any media at all? If so, we show an error and stop the import. Is there any categories where the category ID is greater than 1 (e.g. not a default category)? If so, we also show the error and stop the import.

At that point we should be confident that there will be no overlaps through default data or earlier imported data. So, at that point, we should be safe to delete the default Example Category and proceed with the import.