Just need a clear distinction between these commands.

  1. When to run magento setup:upgrade and
  2. when to run setup:di:compile ?

Also when all cache is disabled, Do we still need to flush the cache and reindex indexer after any change in module ?

4 Answers 4


When To run setup:upgrade command

If you enabled one or more modules, then you will need to run Magento setup:upgrade to update the database schema.


If you write some upgrade schema then you have to fire Magento setup:upgrade command

When do we need to run setup:di:compile command?

The answer is pretty simple This command fulfill the following purpose

  1. Application code generation (factories, proxies, and so on)

  2. Area configuration aggregation (that is, optimized dependency injection configurations per area)

  3. Interceptor generation (that is, optimized code generation of interceptors)

  4. Interception cache generation

  5. Repositories code generation (that is, generated code for APIs)

  6. Service data attributes generation (that is, generated extension classes for data objects)


If your magento is on developer mode then you dont need to fire compile command just need to remove var/di and generation folder(In magento 2.0.x and 2.1.x ) or generated folder in (Magento 2.2.x and above)

  • You are always welcome :) Commented Nov 29, 2017 at 8:06
  • @MurtuzaZabuawala are you sure var/di directory is there in developer mode?
    – MagePsycho
    Commented Dec 5, 2017 at 18:19

bin/magento setup:upgrade :: Is used only if you have any change in module related to installer script. After upgrade need to run bin/magento setup:di:compile.

bin/magento setup:di:compile :: If you are doing any change related to di.xml files or any controller method. No need to run upgrade in this case.

  • I did not need to run bin/magento setup:di:compile for the changes to a Controller to start working in Production mode.
    – Mike Dubs
    Commented May 18, 2022 at 15:00

magento setup:upgrade is roughly the equivalent of n98-magerun sys:setup:run in magento 1 in the sense that it runs your setup scripts but it does something in addition to that in magento 2 since 2.1 if I'm not mistaken. It activates your newly created modules. This will need to be run in developer mode as well as production and default mode. setup:di:compile on the other hand generates your "autogenerated" classes and it'll only need running in production mode as this is done automatically in developer mode.

Also about indexing, you don't need to do that unless you have flat tables enabled and you made a change to one of the entities that is affected by the indexes, eg product atributes, category attributes, category products etc. Clearing cache shouldn't theoretically need to be run if the caches are disabled but I do it all the time to sanity check, keep in mind that setup upgrade clears the caches as well.

I hope this answers your question.


setup:upgrade When you have made changes in module files you have to run setup:upgrade command

setup:di:compile When you have made changes in module / layout confiugrations then you have to run setup:di:compile command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.