Magento stores a lot of data in the database to optimize the performance of your store. However, once you update any of that data, the system starts indexing it to restore the changes in the database tables. That's exactly when the "One or more indexers are invalid. Make sure your Magento cron job is running" error appears in the admin panel.
It is one of the most common Magento errors all Magento users come across when working with Magento.
It might seem just annoying admin notice, but there is more than that behind it. Today you'll learn why "One or more indexers are invalid" appears and how you can easily fix it from the admin panel or via CLI.
Why "One or more indexers are invalid" error appears?
Since Magento is a complex system it has a special feature to schedule and run store tasks automatically — Magento cron jobs. Except for sending newsletters and notifications, updating catalog price rules and currency rates, cron tasks also run reindex.
So, usually, Magento reindex is run automatically. However, if there is something wrong with the cron jobs you see the "One or more indexers are invalid. Make sure your Magento cron job is running" error.
In this case, you will have to reindex manually to make the changes updated to the database.
Fix "One or more indexers are invalid" error in Magento
To solve the "One or more indexers are invalid" error you have to check if the reindex mode and the cron jobs are set up correctly and run the reindex.
1. Check Reindex Mode in the Admin
Navigate to System > Index Management and explore the indexers and their descriptions. You can also see the indexer modes and change them in the Actions dropdown.
- Update on Save — Magento is reindexed automatically after every data update.
- Update by Schedule — reindex runs by cron jobs according to the configured schedule.
- Invalidate Index — disables the indexers.
Also, if you like you can also check indexers mode and status via CLI:
bin/magento indexer:status
Note: if you want to change the mode for indexers either from the admin panel or console, remember to switch to developer mode and disable cron to avoid database locks.
To change the mode:
bin/magento indexer:set-mode {realtime|schedule} [indexer]
- realtime — sets specified indexers to be updated on save
- schedule — sets specified indexers to be updated on cron schedule
- indexer — list of indexers separated by spaces
2. Run Reindex
Regardless of the mode, you can reindex Magento from the admin panel or via the command line. However, some other commands will come in handy too.
To see all indexers in Magento:
php bin/magento indexer:info
To reindex all Magento indexers:
php bin/magento indexer:reindex
To reindex some specific indexers:
bin/magento indexer:reindex [indexer]
e.g bin/magento indexer:reindex catalog_product_price
3. Check Cron Jobs
Once you run the reindex, Magento should create the cron job for this particular task. Unfortunately, sometimes not everything goes as expected so some cron jobs might be missing.
To install missing cron jobs in Magento:
php bin/magento cron:install
To run all cron jobs in Magento:
php bin/magento cron:run
You can also run cron jobs manually from the admin panel if you like.
After you run the cron jobs the indexers will be reindexed and the "One or more indexers are invalid" error in Magento 2 should be resolved. Besides, if you go to the System > Index Management you will see all indexers being run.