Magento CE 1.7.0.2 – Fixing SQLSTATE[23000] Integrity Constraint Violation

ce-1.7.0.2

I'm getting this error and it is keeping me busy all day. I get it when I log in on the admin page. After going back to /admin I get the same error. The magento version is 1.7.x

things I have undertaken so far (among the things I still can remember)

  • clear browser cache
  • clear cache (db & files)
  • clear sessions
  • clear locks
  • execute

    TRUNCATE mage_dataflow_batch_export ; TRUNCATE mage_dataflow_batch_import ; TRUNCATE mage_log_customer ; TRUNCATE mage_log_quote ; TRUNCATE mage_log_summary ; TRUNCATE mage_log_summary_type ; TRUNCATE mage_log_url ; TRUNCATE mage_log_url_info ; TRUNCATE mage_log_visitor ; TRUNCATE mage_log_visitor_info ; TRUNCATE mage_log_visitor_online ; TRUNCATE mage_report_event ;

    the XXXXX is for customer's privacy


    There has been an error processing your request

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

    Trace:
    #0 /var/www/vhosts/xxxxxx/httpdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(111): Zend_Db_Statement_Pdo->_execute(Array)
    #1 /var/www/vhosts/xxxxx/httpdocs/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
    #2 /var/www/vhosts/xxxxxx/httpdocs/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
    #3 /var/www/vhosts/xxxxxxxx/httpdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `adminnotification_inbox` (`severity`, `date_added`, `title`, `description`, `url`) VALUES (?, ?, ?, ?, ?)', Array)
    #4 /var/www/vhosts/xxxxxx/httpdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `adminnotification_inbox` (`severity`, `date_added`, `title`, `description`, `url`) VALUES (?, ?, ?, ?, ?)', Array)
    #5 /var/www/vhosts/xxxxxxxx/httpdocs/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `adminnotification_inbox` (`severity`, `date_added`, `title`, `description`, `url`) VALUES (?, ?, ?, ?, ?)', Array)
    #6 /var/www/vhosts/xxxxxxx/httpdocs/app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php(120): Zend_Db_Adapter_Abstract->insert('adminnotification_inbox', Array)
    #7 /var/www/vhosts/xxxxxxx/httpdocs/app/code/core/Mage/AdminNotification/Model/Inbox.php(118): Mage_AdminNotification_Model_Resource_Inbox->parse(Mage_AdminNotification_Model_Inbox, Array)
    #8 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/AdminNotification/Model/Feed.php(97): Mage_AdminNotification_Model_Inbox->parse(Array)
    #9 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/AdminNotification/Model/Observer.php(50): Mage_AdminNotification_Model_Feed->checkUpdate()
    #10 /var/www/vhosts/xxxxxxxx/httpdocs/app/code/core/Mage/Core/Model/App.php(1338): Mage_AdminNotification_Model_Observer->preDispatch(Varien_Event_Observer)
    #11 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Mage_AdminNotification_Model_Observer, 'preDispatch', Varien_Event_Observer)
    #12 /var/www/vhosts/xxxxxx/httpdocs/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('controller_action_predispatch', Array)
    #13 /var/www/vhosts/xxxxx/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(528): Mage->dispatchEvent('controller_action_predispatch', Array)
    #14 /var/www/vhosts/xxxxxxx/httpdocs/app/code/core/Mage/Adminhtml/Controller/Action.php(160): Mage_Core_Controller_Varien_Action->preDispatch()
    #15 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(408): Mage_Adminhtml_Controller_Action->preDispatch()
    #16 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
    #17 /var/www/vhosts/xxxxxx/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Mage_Core_Controller_Request_Http)
    #18 /var/www/vhosts/xxxxxxx/httpdocs/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
    #19 /var/www/vhosts/xxxxx/httpdocs/app/Mage.php(683): Mage_Core_Model_App->run(Array)
    #20 /var/www/vhosts/xxxxx/httpdocs/index.php(89): Mage->run('', 'store')

I find 0 and PRIMARY odd in this case…
thanks
Thomas

Best Answer

It sounds like auto-increment is disabled on the primary-key of that table.

That or the data-type is wrong.