8

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 ?

5

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.

Or

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)

http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-compiler.html

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 :) – Murtuza Zabuawala Nov 29 '17 at 8:06
  • @MurtuzaZabuawala are you sure var/di directory is there in developer mode? – MagePsycho Dec 5 '17 at 18:19
5

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.

1

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.

0

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, privacy policy and cookie policy

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