Bug #23157 Bug Fixed

Integrity constraint violation

Version: 3.5.8 Reporter: Simon Job

Exception Caught
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4725-1683' for key 'PRIMARY':
INSERT INTO `exp_category_posts` (`entry_id`, `cat_id`) VALUES ('4725', 1683)
ee/legacy/database/drivers/mysqli/mysqli_connection.php:122

I am seeing this error on editing entries after upgrading from 3.5.7 to 3.5.8. I have tried to determine if this is related to creating new entries via the CP/Channel Form and then editing via the CP/Channel Form, but I’ve been unable to isolate.

  • Is this happening for you when editing all entries, or just a few specific entries?

    Derek Jones
    17th June, 2017 at 7:54pm
  • I just tried an entry that was made before the 3.5.8 update. I opened an existing entry, no changes and pressed Save & Close. Same entry (with different entry_id, cat_id).

    Tried another, older, entry - same thing.

    Therefore, seems like all entries.

    Simon Job
    17th June, 2017 at 11:47pm
  • Can you click the “Show” link on the Stack Trace and cut and paste it into a code block here please? Thanks!

    Derek Jones
    19th June, 2017 at 9:28am
  • #0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(137): CI_DB_mysqli_connection->query('INSERT INTO `ex...')
    #1 ee/legacy/database/DB_driver.php(297): CI_DB_mysqli_driver->_execute('INSERT INTO `ex...')
    #2 ee/legacy/database/DB_driver.php(203): CI_DB_driver->simple_query('INSERT INTO `ex...')
    #3 ee/legacy/database/DB_active_rec.php(1462): CI_DB_driver->query('INSERT INTO `ex...')
    #4 ee/EllisLab/ExpressionEngine/Service/Model/Relation/HasAndBelongsToMany.php(121): CI_DB_active_record->insert('category_posts')
    #5 ee/EllisLab/ExpressionEngine/Service/Model/Relation/HasAndBelongsToMany.php(157): EllisLab\ExpressionEngine\Service\Model\Relation\HasAndBelongsToMany->insert(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry), Array)
    #6 ee/EllisLab/ExpressionEngine/Service/Model/Association/Diff.php(82): EllisLab\ExpressionEngine\Service\Model\Relation\HasAndBelongsToMany->set(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry), Array)
    #7 ee/EllisLab/ExpressionEngine/Service/Model/Association/Association.php(202): EllisLab\ExpressionEngine\Service\Model\Association\Diff->commit()
    #8 ee/EllisLab/ExpressionEngine/Service/Model/Model.php(374): EllisLab\ExpressionEngine\Service\Model\Association\Association->save()
    #9 ee/EllisLab/ExpressionEngine/Model/Content/ContentModel.php(198): EllisLab\ExpressionEngine\Service\Model\Model->save()
    #10 ee/EllisLab/ExpressionEngine/Controller/Publish/AbstractPublish.php(295): EllisLab\ExpressionEngine\Model\Content\ContentModel->save()
    #11 ee/EllisLab/ExpressionEngine/Controller/Publish/Edit.php(483): EllisLab\ExpressionEngine\Controller\Publish\AbstractPublish->saveEntryAndRedirect(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry))
    #12 [internal function]: EllisLab\ExpressionEngine\Controller\Publish\Edit->entry('4716')
    #13 ee/EllisLab/ExpressionEngine/Core/Core.php(189): call_user_func_array(Array, Array)
    #14 ee/EllisLab/ExpressionEngine/Core/Core.php(94): EllisLab\ExpressionEngine\Core\Core->runController(Array)
    #15 ee/EllisLab/ExpressionEngine/Boot/boot.php(151): EllisLab\ExpressionEngine\Core\Core->run(Object(EllisLab\ExpressionEngine\Core\Request))
    #16 admin.php(143): require_once('...')
    #16 admin.php(143): require_once('...')
    Simon Job
    19th June, 2017 at 9:38am
  • Hi Simon, I’m having trouble reproducing this locally and not sure how it can happen, we have multiple checks in place to prevent duplicate pivot table rows. Could you submit a support ticket with login details so we can take a closer look on your install? It’d be really helpful to have access to an install where this is happening.

    Kevin Cupp
    19th June, 2017 at 2:42pm
  • I am getting the same error on a fresh install of 3.5.9. It is occurring for me on an entry in a channel with two category groups assigned. exp_category_posts is updating correctly despite the exception. I have another entry in a channel with only one category group assigned and it is not erroring out.

    AnotherMuse
    25th June, 2017 at 12:20am
  • Hi there,

    got the same behaviour once tried to create/edit entries:

    SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5761-6' for key 'PRIMARY':
    INSERT INTO `exp_category_posts` (`entry_id`, `cat_id`) VALUES ('5761', '6')
    
    ee/legacy/database/drivers/mysqli/mysqli_connection.php:122

    It appeared after upgrading from EE 3.5.4 to 3.5.9, before that all was fine.

    Stack Trace:

    #0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(137): CI_DB_mysqli_connection->query('INSERT INTO `ex...')
    #1 ee/legacy/database/DB_driver.php(297): CI_DB_mysqli_driver->_execute('INSERT INTO `ex...')
    #2 ee/legacy/database/DB_driver.php(203): CI_DB_driver->simple_query('INSERT INTO `ex...')
    #3 ee/legacy/database/DB_active_rec.php(1462): CI_DB_driver->query('INSERT INTO `ex...')
    #4 ee/EllisLab/ExpressionEngine/Service/Model/Relation/HasAndBelongsToMany.php(121): CI_DB_active_record->insert('category_posts')
    #5 ee/EllisLab/ExpressionEngine/Service/Model/Relation/HasAndBelongsToMany.php(157): EllisLab\ExpressionEngine\Service\Model\Relation\HasAndBelongsToMany->insert(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry), Array)
    #6 ee/EllisLab/ExpressionEngine/Service/Model/Association/Diff.php(82): EllisLab\ExpressionEngine\Service\Model\Relation\HasAndBelongsToMany->set(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry), Array)
    #7 ee/EllisLab/ExpressionEngine/Service/Model/Association/Association.php(202): EllisLab\ExpressionEngine\Service\Model\Association\Diff->commit()
    #8 ee/EllisLab/ExpressionEngine/Service/Model/Model.php(374): EllisLab\ExpressionEngine\Service\Model\Association\Association->save()
    #9 ee/EllisLab/ExpressionEngine/Model/Content/ContentModel.php(198): EllisLab\ExpressionEngine\Service\Model\Model->save()
    #10 ee/EllisLab/ExpressionEngine/Controller/Publish/AbstractPublish.php(295): EllisLab\ExpressionEngine\Model\Content\ContentModel->save()
    #11 ee/EllisLab/ExpressionEngine/Controller/Publish/Edit.php(483): EllisLab\ExpressionEngine\Controller\Publish\AbstractPublish->saveEntryAndRedirect(Object(EllisLab\ExpressionEngine\Model\Channel\ChannelEntry))
    #12 [internal function]: EllisLab\ExpressionEngine\Controller\Publish\Edit->entry('5761')
    #13 ee/EllisLab/ExpressionEngine/Core/Core.php(189): call_user_func_array(Array, Array)
    #14 ee/EllisLab/ExpressionEngine/Core/Core.php(94): EllisLab\ExpressionEngine\Core\Core->runController(Array)
    #15 ee/EllisLab/ExpressionEngine/Boot/boot.php(151): EllisLab\ExpressionEngine\Core\Core->run(Object(EllisLab\ExpressionEngine\Core\Request))
    #16 public_html/gdadmin.php(143): require_once('...')
    #16 public_html/gdadmin.php(143): require_once('...')

    Looking forward for the solution.

    Thank you.

    annapoli
    25th June, 2017 at 1:45pm
  • Sorry all. We’ve found a fix for this and it should be out in a release probably tomorrow.

    Kevin Cupp
    26th June, 2017 at 12:57pm

You must be signed in to comment on a bug report.

ExpressionEngine News

#eecms, #events, #releases