Magento 2.1 – Cannot Generate Sitemap Due to Missing Query

magento-2.1sitemaps

I recently set my site live, and I was attempting to setup the sitemap.xml file, unfortunately it generates the (what seems common) and vague error "We can't generate the sitemap right now."

A little info first:
Magento CE 2.1.3, php 7.0.16, nginx hosted service.

However, when I look into my log files, this error is generated in the system.log file:

    [2017-03-10 20:38:13] main.CRITICAL: Exception message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2_name.value' in 'field list', query was: SELECT `e`.`entity_id`, `e`.`entity_id`, `e`.`updated_at`, `url_rewrite`.`request_path` AS `url`, IFNULL(t2_name.value, t1_name.value) AS `name`, IFNULL(t2_thumbnail.value, t1_thumbnail.value) AS `thumbnail` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_website` AS `w` ON e.entity_id = w.product_id
 LEFT JOIN `url_rewrite` ON e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND url_rewrite.metadata IS NULL AND url_rewrite.store_id = '31' AND url_rewrite.entity_type = 'product'
 LEFT JOIN `catalog_product_entity_int` AS `t1_visibility` ON e.entity_id = t1_visibility.entity_id AND t1_visibility.store_id = 0 AND t1_visibility.attribute_id = '99'
 LEFT JOIN `catalog_product_entity_int` AS `t2_visibility` ON t1_visibility.entity_id = t2_visibility.entity_id AND t1_visibility.attribute_id = t2_visibility.attribute_id AND t2_visibility.store_id = '31'
 LEFT JOIN `catalog_product_entity_int` AS `t1_status` ON e.entity_id = t1_status.entity_id AND t1_status.store_id = 0 AND t1_status.attribute_id = '97'
 LEFT JOIN `catalog_product_entity_int` AS `t2_status` ON t1_status.entity_id = t2_status.entity_id AND t1_status.attribute_id = t2_status.attribute_id AND t2_status.store_id = '31'
 LEFT JOIN `catalog_product_entity_varchar` AS `t1_name` ON e.entity_id = t1_name.entity_id AND t1_name.store_id = 0 AND t1_name.attribute_id = '73'
 LEFT JOIN `catalog_product_entity_varchar` AS `t1_thumbnail` ON e.entity_id = t1_thumbnail.entity_id AND t1_thumbnail.store_id = 0 AND t1_thumbnail.attribute_id = '89' WHERE (w.website_id = '1') AND ((IF(t2_visibility.value_id > 0, t2_visibility.value, t1_visibility.value)) IN(3, 2, 4)) AND ((IF(t2_status.value_id > 0, t2_status.value, t1_status.value)) IN(1))
Trace: #0 /home/userhome/public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/userhome/public_html/vendor/magento/zendframework1/library/Zend/Db/Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#2 /home/userhome/public_html/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /home/userhome/public_html/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `e`.`ent...', Array)
#4 /home/userhome/public_html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(465): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `e`.`ent...', Array)
#5 /home/userhome/public_html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(520): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('SELECT `e`.`ent...', Array)
#6 /home/userhome/public_html/vendor/magento/module-sitemap/Model/ResourceModel/Catalog/Product.php(289): Magento\Framework\DB\Adapter\Pdo\Mysql->query(Object(Magento\Framework\DB\Select))
#7 /home/userhome/public_html/vendor/magento/module-sitemap/Model/Sitemap.php(245): Magento\Sitemap\Model\ResourceModel\Catalog\Product->getCollection('31')
#8 /home/userhome/public_html/vendor/magento/module-sitemap/Model/Sitemap.php(338): Magento\Sitemap\Model\Sitemap->_initSitemapItems()
#9 /home/userhome/public_html/vendor/magento/module-sitemap/Controller/Adminhtml/Sitemap/Generate.php(27): Magento\Sitemap\Model\Sitemap->generateXml()
#10 /home/userhome/public_html/vendor/magento/framework/App/Action/Action.php(102): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate->execute()
#11 /home/userhome/public_html/vendor/magento/module-backend/App/AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#12 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#13 /home/userhome/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callParent('dispatch', Array)
#14 /home/userhome/public_html/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Sitemap...', 'dispatch', Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Array, 'adminAuthentica...')
#15 /home/userhome/public_html/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#16 /home/userhome/public_html/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#17 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Sitemap...', 'dispatch', Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Array, 'adminMassaction...')
#18 /home/userhome/public_html/vendor/magento/module-backend/App/Action/Plugin/MassactionKey.php(33): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#19 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#20 /home/userhome/public_html/var/generation/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate/Interceptor.php(26): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callPlugins('dispatch', Array, Array)
#21 /home/userhome/public_html/vendor/magento/framework/App/FrontController.php(55): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#22 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#23 /home/userhome/public_html/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#24 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#25 /home/userhome/public_html/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#26 /home/userhome/public_html/vendor/magento/framework/Interception/Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#27 /home/userhome/public_html/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#28 /home/userhome/public_html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#29 /home/userhome/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#30 /home/userhome/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#31 {main} [] []

Best Answer

Seems there is a thread where is mentioned the same query:

There is also ticket open with the same issue:

By looking the query then t2_name is not found therein joins.

This is added to select in

vendor/magento/module-sitemap/Model/ResourceModel/Catalog/Product.php::getCollection

As also GitHub issues say then this is added only when you have enabled "Add Images to Sitemap".

You should try to disable this option to have at least sitemap without image info.

Related Topic