跳至内容
菜单
此问题已终结
2 回复
13939 查看

How can I rename a field in the model code, e.g. `FooModel`, so that the changes propagate correctly to the database schema?

I would like to rename e.g. `spam` to `beans` in the `FooModel._columns`. But how can I ensure that the same column rename occurs in the database when I update the OpenERP server code?

I can just rename the field in the Python code for the model, of course. But how will Odoo know which field was renamed to what? What if I rename several fields at once? What if I rename one field, delete another, and create another? How can I signal to Odoo which new fields are renames?


形象
丢弃
最佳答案

Hi,

For example :

old :
    spam = fields.Char(string='SPAM')

new :

     beans = fields.Char(oldname='spam',string="SPAM")

"oldname" parameter refer to the previous name of this field, so that ORM can rename it automatically at migration.

形象
丢弃
最佳答案

I rename fields all the time. All that is needed is restarting Odoo, followed by an upgrade of the module that implements the field. Odoo will take care of the schema. 

形象
丢弃
相关帖文 回复 查看 活动
0
12月 24
1324
1
3月 24
2377
1
6月 23
12388
0
1月 23
3100
2
9月 20
4039