9 - Upgrading Modules: -u and -i Flags Explained
Welcome back! If you have been following along and writing your own Odoo code, you have probably hit the most common roadblock every beginner faces:
"I just changed my code, I saved the file, I refreshed my browser... but nothing changed on the screen!"
We have all been there! Odoo does not automatically read your files every time you refresh the page. Because Odoo is built for enterprise performance, it reads your XML views and Python models and stores them deep inside the PostgreSQL database.
To tell Odoo to fetch your new code and put it into the database, you must use the -i (Install) and -u (Update) flags. Let's master them.
1. The -i Flag (Install)
The -i flag stands for Install. You should use this flag only once per database for your specific module.
When you run this command, Odoo looks at your __manifest__.py file, registers your module in the database, runs any installation hooks, and loads your XML files for the very first time.
How to use it:
python3 odoo-bin -c odoo.conf -d my_database -i my_new_module
When to use it:
When you have just finished creating the basic folder structure of a brand-new module.
When you are deploying a module to a client's database for the first time.
Note: If a module is already installed, running -i again usually just acts like an update, but it is considered bad practice. Stick to -u!
2. The -u Flag (Update)
The -u flag stands for Update (or Upgrade). This is the flag you will use 50 times a day as a developer.
Whenever you make a change to an Odoo data file, you must restart the server and pass the -u flag followed by your module's technical name.
How to use it:
python3 odoo-bin -c odoo.conf -d my_database -u my_new_module
When to use it:
You changed an XML file (like adding a new field to a form view).
You added a new access right in your ir.model.access.csv file.
You changed a dependency or version number in your __manifest__.py.
You modified a QWeb template for a PDF report.
3. The "Python vs. XML" Rule
This is a crucial concept that separates juniors from seniors. You don't always need the -u flag!
If you change a Python file (.py): Python code (like a new function or a calculated field) is loaded into the server's RAM. To apply a Python change, you only need to restart the server. You do not need the -u flag.
# Just stop the server (Ctrl+C) and run it again:
python3 odoo-bin -c odoo.conf -d my_database
If you change a Data file (.xml, .csv): Data files are stored in the PostgreSQL database. Restarting the server does nothing. You must use the -u flag so Odoo knows to read the XML file and overwrite the old database record.
4. The Nuclear Option: -u all
Sometimes, you might pull a massive update from GitHub that touches 20 different modules, or you upgrade your base Odoo 19 source code. Instead of trying to guess which modules to update, you can tell Odoo to update everything.
python3 odoo-bin -c odoo.conf -d my_database -u all
⚠️ Warning: Never do this casually on a production server! Updating all forces Odoo to re-evaluate every single module in the system. On a large database, this can take 10 to 30 minutes and might cause unnecessary downtime.
5. Pro-Tips & Advice
💡 PRO TIP: The Developer Mode Flag (--dev=xml) Are you tired of typing -u your_module every single time you move a button in an XML view? Odoo has a built-in cheat code for developers!
If you start your server with the --dev=xml flag, Odoo will read the XML files directly from your hard drive instead of from the database whenever you refresh your browser.
python3 odoo-bin -c odoo.conf -d my_database --dev=xml
With this flag running, you can change your XML, save the file, and simply hit F5 in your browser. The changes will appear instantly! (Note: You still need to restart the server for Python changes).
There are no comments for now.