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

  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)


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.

Tags:

Magento2