19

There are lots of situations in which I change some files in my module in the developer mode but the changes didn't take place in frontend until I run php bin/magento setup:upgrade

Just wanted to know when should we run setup:upgrade command and what's the purpose of it in Magento 2?

It's just so strange for me, because every time I'm doing some changes, they won't be visible until after I run the setup:upgrade command. Even if I delete the var/cache, it's still not visible. Does anyone know any reason for this?

2 Answers 2

27

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

By default, magento setup:upgrade clears compiled code and the cache. Typically, you use magento setup:upgrade to update components and each component can require different compiled classes.

magento setup:upgrade --keep-generated

The optional --keep-generated option should be used only in limited circumstances by experienced system integrators. --keep-generated should never be used in a development environment.

Improper use of this optional parameter can cause errors during code execution.

UPDATE (07/10/17)

As the topic creator asked me:

But its just so strange for me, because everytime I'm doing some changes, they won't be visible until after I run the setup:upgrade command. Even if I delete the var/cache, its still not visible. Do you know any reason for this?

var/cache in Magento 2 is not enough to makes changes visible like Magento 1. In Magento 2, you will need to clears var/generation (and var/di if you compiled code) after you made changes inside your code, especially whenever you change something inside the constructor.

You will also need to clear var/view_preprocessed if you change something inside your template file (.phtml)

The rest will goes to var/cache and var/full_page_cache

Hope this helps.

5
  • Sir, Thanks for your answer. But its just so strange for me, because everytime I'm doing some changes, they won't be visible until after I run the setup:upgrade command. Even if I delete the var/cache, its still not visible. Do you know any reason for this? Commented Apr 25, 2016 at 8:12
  • Maybe you're not clearing enough directories. Maybe the setup:upgrade command is clearing them for you. Look at this page for reference. I am assuming your module is enabled; if not, that also causes issues. Commented Apr 26, 2016 at 13:31
  • @MichelGokan I updated the answer. Commented Jul 10, 2017 at 3:33
  • Do we need to run the setup:upgrade after disabling extensions?
    – Webninja
    Commented Jan 18, 2018 at 15:31
  • 1
    @Webninja Yes, we do. Commented Jan 18, 2018 at 23:04
2

When you enable modules, change modules version you will need to run magento setup:upgrade to update the database schema.

In other cases when you add new data in your class constructors, you need to run magento setup:upgrade because it clear var/generation folder. To understand it, remove write and read permissions for var folder and run the command magento setup:upgrade

You will get an error message like this
Command line user does not have read and write permissions on var/generation directory. Please address this issue before using Magento command line. meaning that this command is clearing folder var/generation. If you want to get your changes without executing magento setup:upgrade command, you need to clear these three folders

rm -rf var/cache/* var/page_cache/* var/generation/*

0

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.