简体   繁体   English

如何解决列 res_partner.<column> 在 Odoo 中不存在?</column>

[英]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例如,“reonp”很好地添加到模型中,但是当我尝试添加“gradjanin”时,Odoo 10 引发错误

代码/错误的图像

I was trying to restart the server我试图重新启动服务器

py 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.这实际上是您在使用新字段扩展模型res.partner时遇到的典型错误。

On starting the Odoo server, every modules python files will be "loaded" so ofcourse your new fields on res.partner , too.在启动 Odoo 服务器时,每个模块 python 文件都将被“加载”,所以当然也会加载res.partner上的新字段。 But that's only on python side or better on the application itself.但这仅在 python 方面或在应用程序本身方面更好。 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.现在尝试使用该应用程序或“在 Odoo 的网络客户端中加载某些内容”将尝试从数据库加载数据,其中新字段没有相应的列。

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.在登录时,Odoo 将加载正在登录的用户。模型res.users继承了整个模型res.partner ,因此 Odoo 试图从数据库加载res.partner数据。 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 )带参数-u (如果系统中有多个数据库带-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 作为服务启动,尝试启动第二个实例,它只会更新模块并在之后立即停止。

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.这就像一个“自我毁灭”的无头 Odoo 实例。 The parameter --no-xmlrpc will be --no-http in Odoo V11+.参数--no-xmlrpc在 Odoo V11+ 中将是--no-http

Tell Odoo in the database to update a module/app.告诉数据库中的 Odoo 更新模块/应用程序。

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

After that just restart Odoo.之后只需重新启动 Odoo。

Or the tricky way :或者棘手的方法

Just go into the Apps menu and open your module/app.只需进入应用程序菜单并打开您的模块/应用程序。 Restart Odoo and update the module/app.重新启动 Odoo 并更新模块/应用程序。 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:我建议使用此 SQL 查询将其手动添加到“res_partner”:

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.您也遇到了“res_users”的这个问题,您不需要重新启动服务。

Before that add depends on manifest for res.partner .在此之前,添加取决于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:由于res_partner模型属于 odoo基础模块,所以每当您将基础模型继承到自定义模块时,尝试在启动odoo 服务时升级模块,在这种情况下如下:

Syntax: py " FILE__PATH_To_odoo-bin " --conf " FILE__PATH_To_odoo.conf " -u MY_CUSTOM_MODULE_NAME语法: 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 py "C:\odoo13\odoo-bin" --conf "C:\odoo13\odoo.conf" -u my_module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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