As an odoo programmer, in the middle of a module or addon development, have you ever experienced something unpleasant, like after you refreshed the browser, suddenly an Internal Server Error message appears as below ?
After we check in the terminal or log file, it turns out that there is a ProgrammingError: column res_partner.max_order_item does not exist error message as shown below.
From the picture above, it can be seen that odoo tell us about max_order_item column or field actually does not exist. Hmmm, is it really not there ? There is, here is a screenshot of my source code, which clearly has a field named max_order_item.
But why does odoo still think the field doesn’t exist ? Strange.
Honestly, when I started my career as an odoo programmer, I considered this error as the most annoying error. Because this error does not always occur, it is difficult to determine the cause. For example on my computer there is no error, but when we try it on the tester’s computer an error appears. Or on my computer and the tester’s computer there is no error, but when we upload the module to the client’s server an error appears.
In the past, I had to spend several days investigating these errors and figuring out how to solve them. Thanks God, finally it’s bear sweet fruit 🙂
It turns out that this error only occurs if we add a new field to a certain model – as far as I know it only occurs in the res.users and res.partner models – while the module or addon where we add this new field has been installed, then we restart the odoo service and refresh the browser.
As study case, let’s say we create a new module or addon with the name of tutorial_field_not_found with a model that inherit to the res.partner model as below.
# -*- coding: utf-8 -*- from odoo import api, fields, models, _ class Partner(models.Model): _inherit = 'res.partner' sales_limit = fields.Float(string='Sales Amount Limit')
Since the tutorial_field_not_found module is a new module, of course we have to restart the odoo service and install it. No problem until here.
Then add a new field like the code below, after installing the module or addon.
# -*- coding: utf-8 -*- from odoo import api, fields, models, _ class Partner(models.Model): _inherit = 'res.partner' sales_limit = fields.Float(string='Sales Amount Limit') # max_order_item field was added after the module has been installed max_order_item = fields.Float(string='Maximum Item in One Order')
Restart the odoo service, then refresh your browser. I can be sure that the Internal Server Error message like in the first image above will appear.
If we change the steps like before adding a new field – in this case the max_order_item field – we perform uninstall action on the tutorial_field_not_found module, then after adding the new fields we reinstall the module, this error will not appear. But this method certainly cannot be performed in a production database, because the existing data will be lost.
The safest action we can do is by changing the state of the ir.module.module model to uninstalled with a SQL command, either through the terminal or via the PGAdmin application, in a database that the error message is appear. Here is how to do it.
-- change the state of the tutorial_field_not_found module to be uninstalled -- so if we restarted the odoo service, this module will not be read by odoo -- then the error will not occur update ir_module_module set state = 'uninstalled' where name = 'tutorial_field_not_found';
After the state of the tutorial_field_not_found module becomes uninstalled, restart the odoo service, refresh the browser, then enter the Apps menu and find the module.
From the image above, we can see that the tutorial_field_not_found module is not installed. It is okay. Click the Install button to install the module again.
With this way we can solve the column does not exist error in a more safe way. It’s a little complicated, but fortunately not all models will cause this error if we add a new field to that model, as far as I know this error only occurs in the res.users and res.partner models only.
I got some feedback from several twitter users when I posted this article on that site, the first feedback is, to solve this error, we can upgrade the module via the command line, no need to change the state of ir.module.module model. To do this, please read at the odoo forum here. I have tested it, and this method works nicely. Thank you @prdgmdgtl and @oasis_agano for your suggestion.
The second feedback is another condition that can cause this error, but unfortunately I still don’t know how to reproduce it.