Magento2 Reindex Error – No Such Entity

magento-2.0magento2migrationreindex

I have successfully migrated the catalog from Magento 1.9.2.3 to Magento 2.0.2.
After the migration, I did reindex using the command php bin/magento indexer:reindex.

All is reindexed successfully, except indexes catalog_category_product and catalog_product_category, returning No such entity. in shell and notification Reindex Required in admin.
I've checked var/log/ but no errors.

As a result, products are added to categories in the backend but categories show up empty on the frontend.

What might cause this problem?
How can I debug?

Best Answer

In addition to Raphael:

I Debugged this code with altering the exception constructor for debug purposes (either by xdebug or old dumps). Alter the construct of the exception for now (the file is \lib\internal\Magento\Framework\Exception\NoSuchEntityException.php)

$trace = debug_backtrace();
var_dump($trace[1]['class'] . '::' . $trace[1]['function'] . '('.$trace[1]['line'] .')';
die();

After that go up one stack and check the arguments given (the args are also available in the debug backtrace, but dumping magento objects isn't really browser friendly).

Came to the conclusion, that it was in the storeGroupRepository where it couldn't find the group id. Dived into the store tables and saw a few lines in the store table that were referencing a store_group that wasn't in the store_group table(store group not exist in relevant table).

Removed the faulty store lines and the error has been gone ever since.

But, keep in mind that it can also be in a different table/other reason. for example website, store itself or store group in this case. So that is always a little search you have to perform yourself.

Also found out that there were quite a lot of references to these stores and also removed them manually in the db. This can be a tedious work but it will solve the problem.

And don't forget to remove your hacks.

Related Topic