Just need a clear distinction between these commands.
- When to run magento setup:upgrade and
- 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 ?
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
Application code generation (factories, proxies, and so on)
Area configuration aggregation (that is, optimized dependency injection configurations per area)
Interceptor generation (that is, optimized code generation of interceptors)
Interception cache generation
Repositories code generation (that is, generated code for APIs)
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
andgeneration
folder(In magento 2.0.x and 2.1.x ) or generated folder in (Magento 2.2.x and above)
var/di
directory is there in developer mode?
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.
bin/magento setup:di:compile
for the changes to a Controller to start working in Production mode.
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