从生产数据库如何将int字段更改为char

问题描述 投票:1回答:1

从生产数据库中,我需要将一个字段从int更改为char。

当我在本地尝试时,我丢失了存储在该字段中的所有数据。

解决方案是什么?

python odoo odoo-10
1个回答
0
投票

[更改字段field_name的类型时,Odoo将原始field重命名为field_name_moved0不会从数据库中删除它,如果可以访问数据库,则可以通过简单的方法轻松设置该值查询:

-- just make sure you cast the value of field_name_moved0 to varchar
update your_table_name set field_name = field_name_moved0::varchar where field_name_moved0 is not null;

注:如果再次更改字段的类型,名称将为field_name_moved1

© www.soinside.com 2019 - 2024. All rights reserved.