Magento 2 indexer returns “No such entity”
You may discovered a weird error message, that Magento 2 indexer returns with “No such entity“. This sometimes happens if you create a clone of your shop and some SQL indexers went wrong. The problem: you shop is broken. I show you how to fix this.
Magento 2 indexer returns “No such entity”
First of all: if you copied your live database to your dev shop, then you will probably get errors. If you run a full index like I described in my indexer post, the you will see the following output:
Normally, this is not the only problem. If you log into your adminhtml, you may discover reports with following error message:
1 | Requested store is not found |
which comes from Magento\Store\Model\StoreRepository->getById(0). Every site that needs products or categories ends with such a report. It looks as if something happens to your admin store, the store with website id 0.
Solution
This problem is solved by resetting store_ids with following SQL statements:
1 2 3 4 5 6 | SET FOREIGN_KEY_CHECKS=0; UPDATE `store` SET store_id = 0 WHERE code='admin'; UPDATE `store_group` SET group_id = 0 WHERE name='Default'; UPDATE `store_website` SET website_id = 0 WHERE code='admin'; UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN'; SET FOREIGN_KEY_CHECKS=1; |
We disable foreign key checks and manually set store_id to 0, which is by default your admin store or default store for all categories and products. Please also check, that your admin store has website_id 0 and not the highest number in your store_website table. SQL generates a problem if you fill this table with data, because auto increment starts with 1 and not as expected with 0 for admin store. So admin is normally the store with highest id -> just replace its website_id value to 0.
Conclusion
I showed you how to fix “No such entity” which may be returned by your indexer. This problem sometimes happens if you clone your database for a new dev system.