我在创建模型时创建了一个类型的字段:
wrong_field = fields.Char('Wrong')
现在,我想更正此字段并将日期迁移到新字段。我在 odoo 文档中找到了关键字“oldname”。所以我像这样改变我的领域:
right_field = fields.Char('Right', oldname='wrong_field')
但它不起作用,新字段没有数据。
为什么这不起作用?我该如何解决?
谢谢!
我已经解决了。根据以下编码:
def update_db(self, model, columns):
""" Update the database schema to implement this field.
:param model: an instance of the field's model
:param columns: a dict mapping column names to their configuration in database
:return: ``True`` if the field must be recomputed on existing rows
"""
if not self.column_type:
return
column = columns.get(self.name)
if not column and hasattr(self, 'oldname'):
# column not found; check whether it exists under its old name
column = columns.get(self.oldname)
if column:
sql.rename_column(model._cr, model._table, self.oldname, self.name)
# create/update the column, not null constraint, indexes
self.update_db_column(model, column)
self.update_db_notnull(model, column)
self.update_db_index(model, column)
return not column
rigth_field 不能放在桌子上。先从数据库中删除表中的right_field,再更新。