When to run following commands in magento2?
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)
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.