Search code examples
pythonodooodoo-10

From the production database how to change int field to char


From the production DB I need to change a field from int to char.

When I tried in local I lost all the data which is stored in the field.

What is the solution?


Solution

  • When you change the type of field field_name, Odoo rename the original field to field_name_moved0 and create a new one with name field_name, If you have access to the database you can set the value easily by a simple query:

    -- 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;
    

    Note: If you change the type of field again, the name will be field_name_moved1.