Title: Bug in SQL query when creating galleries
Last modified: January 9, 2019

---

# Bug in SQL query when creating galleries

 *  Resolved [jestep](https://wordpress.org/support/users/jestep/)
 * (@jestep)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/bug-in-sql-query-when-creating-galleries/)
 * When I try to create a new gallery using nextgen, it is trying to add a new gallery
   to the database using a primary key of zero.
 * `[09-Jan-2019 16:48:04 UTC] WordPress database error Duplicate entry '0' for 
   key 'PRIMARY' for query INSERT INTO`wp_ngg_gallery`(`title`,`author`,`extras_post_id`,`
   gid`,`name`,`slug`,`path`,`pageid`,`previewpic`) VALUES ('Test Gallery 3', '1','
   61', '0', 'test-gallery-3', 'Test-Gallery-3-1', '/wp-content/gallery/test-gallery-
   3-1/', '0', '0') made by require('wp-blog-header.php'), require_once('wp-load.
   php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('
   init'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, M_Ajax-
   >serve_ajax_request, C_Ajax_Controller->index_action, ExtensibleObject->call_method,
   ExtensibleObject->__call, ExtensibleObject->_exec_cached_method, ReflectionMethod-
   >invokeArgs, A_NextGen_AddGallery_Ajax->upload_image_action, C_DataMapper_Model-
   >save, C_Gallery_Mapper->save, ExtensibleObject->__call, ExtensibleObject->_exec_cached_method,
   ReflectionMethod->invokeArgs, Mixin_DataMapper_Driver_Base->save, C_Gallery_Mapper-
   >_save_entity, ExtensibleObject->__call, ExtensibleObject->_exec_cached_method,
   ReflectionMethod->invokeArgs, Mixin_Gallery_Mapper->_save_entity, Mixin->call_parent,
   ExtensibleObject->call_method, ExtensibleObject->__call, ExtensibleObject->_exec_cached_method,
   ReflectionMethod->invokeArgs, C_CustomTable_DataMapper_Driver_Mixin->_save_entity,
   C_Gallery_Mapper->_create, ExtensibleObject->__call, ExtensibleObject->_exec_cached_method,
   ReflectionMethod->invokeArgs, Mixin_NextGen_Table_Extras->_create, Mixin->call_parent,
   ExtensibleObject->call_method, ExtensibleObject->__call, ExtensibleObject->_exec_cached_method,
   ReflectionMethod->invokeArgs, C_CustomTable_DataMapper_Driver_Mixin->_create`
 * Brand new installation, running twenty16. From the debug log, it is explicitly
   trying to set gid to zero, which should not be happening. NULL would be fine,
   but zero is going to cause problems. I haven’t dug through the actual code in
   the plugin, but something isn’t right here.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [gabyimagely](https://wordpress.org/support/users/gabyimagely/)
 * (@gabyimagely)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/bug-in-sql-query-when-creating-galleries/#post-11074608)
 * Hi [@jestep](https://wordpress.org/support/users/jestep/)!
 * Could you please share with us this information?
    Go to Gallery > Overview > 
   Site details Copy and paste the information you find there
 * Please, share with us your current version of NextGen Gallery and WordPress.
 * Keep us posted.
 * – Gaby, Customer Support Imagely
 *  Thread Starter [jestep](https://wordpress.org/support/users/jestep/)
 * (@jestep)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/bug-in-sql-query-when-creating-galleries/#post-11075021)
 * Thanks for the reply. I see the problem now. The database had sql-mode NO_AUTO_VALUE_ON_ZERO
   turned on.
 *  [Mihai Ceban](https://wordpress.org/support/users/mihaiimagely/)
 * (@mihaiimagely)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/bug-in-sql-query-when-creating-galleries/#post-11076898)
 * Hi [@jestep](https://wordpress.org/support/users/jestep/),
 * Great. Please keep us updated on your results after disabling it.
 * Mihai

Viewing 3 replies - 1 through 3 (of 3 total)

 The topic ‘Bug in SQL query when creating galleries’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Mihai Ceban](https://wordpress.org/support/users/mihaiimagely/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/bug-in-sql-query-when-creating-galleries/#post-11076898)
 * Status: resolved