During the last two days I have been trying to install a custom module in Odoo 13. I got the same error over and over again, telling that a column didn’t exist in the model that I was creating (the variable in the class did, indeed, exist), I show the error down below.
The python code of the module is the following:
from odoo import models, fields, api class OfferStage(models.Model): _name = 'offer.stage' _description = 'Offer stage' name = fields.Char() revisable = fields.Boolean() sequence = fields.Integer() modificable = fields.Boolean() notify_jefe = fields.Boolean() fold = fields.Boolean() convertible = fields.Boolean() notify_personal = fields.Boolean() notify_jefe_area = fields.Boolean()
And the error I get:
Error: Odoo Server Error Traceback (most recent call last): File "/opt/odoo/odoo/odoo/http.py", line 624, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/odoo/http.py", line 310, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/opt/odoo/odoo/odoo/tools/pycompat.py", line 14, in reraise raise value File "/opt/odoo/odoo/odoo/http.py", line 669, in dispatch result = self._call_function(**self.params) File "/opt/odoo/odoo/odoo/http.py", line 350, in _call_function return checked_call(self.db, *args, **kwargs) File "/opt/odoo/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/opt/odoo/odoo/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/opt/odoo/odoo/odoo/http.py", line 915, in __call__ return self.method(*args, **kw) File "/opt/odoo/odoo/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1331, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1319, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 387, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 374, in _call_kw_multi result = method(recs, *args, **kwargs) File "<decorator-gen-60>", line 2, in button_immediate_install File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 72, in check_and_log return method(self, *args, **kwargs) File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 463, in button_immediate_install return self._button_immediate_function(type(self).button_install) File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "/opt/odoo/odoo/odoo/modules/registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/opt/odoo/odoo/odoo/modules/loading.py", line 421, in load_modules processed_modules += load_marked_modules(cr, graph, File "/opt/odoo/odoo/odoo/modules/loading.py", line 313, in load_marked_modules loaded, processed = load_module_graph( File "/opt/odoo/odoo/odoo/modules/loading.py", line 202, in load_module_graph registry.init_models(cr, model_names, {'module': package.name}, new_install) File "/opt/odoo/odoo/odoo/modules/registry.py", line 369, in init_models model._auto_init() File "/opt/odoo/odoo/odoo/models.py", line 2529, in _auto_init new = field.update_db(self, columns) File "/opt/odoo/odoo/odoo/fields.py", line 857, in update_db self.update_db_notnull(model, column) File "/opt/odoo/odoo/odoo/fields.py", line 921, in update_db_notnull sql.drop_not_null(model._cr, model._table, self.name) File "/opt/odoo/odoo/odoo/tools/sql.py", line 119, in drop_not_null cr.execute('ALTER TABLE "{}" ALTER COLUMN "{}" DROP NOT NULL'.format(tablename, columnname)) File "/opt/odoo/odoo/odoo/sql_db.py", line 173, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/odoo/odoo/sql_db.py", line 250, in execute res = self._obj.execute(query, params) psycopg2.errors.UndefinedColumn: column "name" of relation "offer_stage" does not exist
After some trial and error, I tried to install a default module that is created with odoo-bin scaffold, and what was my surprise when I cound’t install it neither.
The error I get when installing the default module is a collision with other tables of odoo packages, since I am in a test environment I tried removing those packages and, when trying to reinstall, the same error arose but with a different package. I can’t figure out why this happens because, a priori, my package only depends on ‘base’.
The code of the default module created with scaffold:
# -*- coding: utf-8 -*- from odoo import models, fields, api class borrar(models.Model): _name = 'borrar.borrar' _description = 'borrar.borrar' name = fields.Char() value = fields.Integer() value2 = fields.Float(compute="_value_pc", store=True) description = fields.Text() @api.depends('value') def _value_pc(self): for record in self: record.value2 = float(record.value) / 100
The error I get:
Error: Odoo Server Error Traceback (most recent call last): File "/opt/odoo/odoo/odoo/http.py", line 624, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo/odoo/http.py", line 310, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/opt/odoo/odoo/odoo/tools/pycompat.py", line 14, in reraise raise value File "/opt/odoo/odoo/odoo/http.py", line 669, in dispatch result = self._call_function(**self.params) File "/opt/odoo/odoo/odoo/http.py", line 350, in _call_function return checked_call(self.db, *args, **kwargs) File "/opt/odoo/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/opt/odoo/odoo/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/opt/odoo/odoo/odoo/http.py", line 915, in __call__ return self.method(*args, **kw) File "/opt/odoo/odoo/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1331, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1319, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 387, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/odoo/api.py", line 374, in _call_kw_multi result = method(recs, *args, **kwargs) File "<decorator-gen-60>", line 2, in button_immediate_install File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 72, in check_and_log return method(self, *args, **kwargs) File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 463, in button_immediate_install return self._button_immediate_function(type(self).button_install) File "/opt/odoo/odoo/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "/opt/odoo/odoo/odoo/modules/registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/opt/odoo/odoo/odoo/modules/loading.py", line 467, in load_modules env[model]._check_removed_columns(log=True) File "/opt/odoo/odoo/odoo/models.py", line 2447, in _check_removed_columns tools.drop_not_null(cr, self._table, row['attname']) File "/opt/odoo/odoo/odoo/tools/sql.py", line 119, in drop_not_null cr.execute('ALTER TABLE "{}" ALTER COLUMN "{}" DROP NOT NULL'.format(tablename, columnname)) File "/opt/odoo/odoo/odoo/sql_db.py", line 173, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/odoo/odoo/sql_db.py", line 250, in execute res = self._obj.execute(query, params) psycopg2.errors.UndefinedColumn: column "rows" of relation "product_packaging" does not exist
However, the table borrar_borrar does get created:
link to image showing table in pgadmin4
This only happens with modules created by me, I have downloaded several modules from github and the official Odoo store and all of them install flawlessly.
Note: for ease of maintenance I have the modules in a git repository and I have soft-linked them to the custom-addons folder in the odoo directory. I have also tried placing them directly in the directory and the errors are the same.
Advertisement
Answer
I found out the solution. I’m writing it here in case someone face the same problem in the future.
The issue was that I had a Foreign Data Wrapper (FDW) to read data from another database and, for some reason, it was causing some kind of interference with the database I was working on. When I removed the FDW, everything worked as expected.