我想重命名odoo字段名称

时间:2018-01-25 09:40:57

标签: odoo odoo-11

我在创建模型时创建了一个带有类型的字段:

wrong_field = fields.Char('Wrong')

现在,我想更正此字段并将日期迁移到新字段。我找到了关键字" oldname"在odoo文档中。所以我改变了我的领域:

right_field = fields.Char('Right', oldname='wrong_field')

但它没有用,新领域没有数据 为什么这不起作用?我怎么解决呢? 谢谢!

1 个答案:

答案 0 :(得分:0)

我已经解决了。根据以下编码:

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,然后再次更新。

相关问题