简体   繁体   中英

How to solve column res_partner.<column> does not exist in Odoo?

As an example, 'reonp' is a nicely added in model, but when I tried to add a 'gradjanin', Odoo 10 raise an error

代码/错误的图像

I was trying to restart the server

py

class komPartnerrReon(models.Model):
    _inherit = 'res.partner'

    reonp = fields.Many2one('kom.reon')
    gradjanin = fields.Boolean('Gradjanin', default=False) #There was an error after adding this line of code

error

  File "C:\odoo-10.0\odoo\sql_db.py", line 231, in execute
      res = self._obj.execute(query, params)
ProgrammingError: column res_partner.gradjanin does not exist
LINE 1: ...id" as "parent_id","res_partner"."name" as "name","res_partn...

That's actually the classic error you get on extending model res.partner with new fields.

On starting the Odoo server, every modules python files will be "loaded" so ofcourse your new fields on res.partner , too. But that's only on python side or better on the application itself. Now trying to use the application or "loading something in Odoo's webclient" will then try to load data from database, where the new fields don't have the corresponding columns.

For example the login. On login Odoo will load the user, which is logging in. Model res.users inherits the whole model res.partner , so that Odoo is trying to load res.partner data from database. And boom the error.

It can also happen if already logged in. For example in a formular view of a model with chatter. The chatter loads followers, which are partners, so boom the error.

What can you do, to fix that?

Update the module on server start

with parameter -u (and if more than one database in the system with -d )

odoo -c <path_to_config> -u my_module -d my_database

If that's not possible ,

for example in productive systems or because Odoo is started as service, try to start a second instance which will just update the module and stop after that immediately.

odoo -c <path_to_config> -u my_module -d my_database --max-cron-threads=0 --stop-after-init --no-xmlrpc

That's like a "self-destroying" headless Odoo instance. The parameter --no-xmlrpc will be --no-http in Odoo V11+.

Tell Odoo in the database to update a module/app.

UPDATE ir_module_module set state = 'to upgrade' where name = 'my_module';

After that just restart Odoo.

Or the tricky way :

Just go into the Apps menu and open your module/app. Restart Odoo and update the module/app. That's the fastest way, but you guess it, you will sometimes forget to do it. And it's only working before you get the error;-)

I suggest to add it manually to 'res_partner' using this SQL query:

ALTER TABLE res_partner 
    ADD COLUMN gradjanin BOOLEAN;

You face this problem with 'res_users' too, and you don't need to restart the service.

Before that add depends on manifest for res.partner .

'depends': ['base'],

And update the module. Try again !

As res_partner model belongs to odoo base module so whenever you inheriting the base model to the custom module, try to upgrade the module while starting the odoo service , in this case as below:

Syntax: py " FILE__PATH_To_odoo-bin " --conf " FILE__PATH_To_odoo.conf " -u MY_CUSTOM_MODULE_NAME

Example:

py "C:\odoo13\odoo-bin" --conf "C:\odoo13\odoo.conf" -u my_module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM