Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
9387 Zobrazení

Dear all,

I would like to change the data type from float to string. Since I already have data on my db I would like to know what I need to consider / do. 

What will happen if I change the type? Do I need to migrate data, if yes how?

Will future data just be saved as string or what happens if I change the data type?

Would really appreciate if you could help me!
Thanks in advance!

Avatar
Zrušit

So this means I have to update and after this migrate via SQL statements? Is this the standard way to go?


Yes. There is no guarantee that either Odoo or PostgreSQL can convert data from one type to another with 100% accuracy, so the safeguard that Ibrahim describes has been created to keep old data so that YOU are responsible and can make sure it is converted with 100% accuracy. This is part of the reason it is not considered a PostgreSQL best practice to change a datatype in a column. The other parts: an exclusive lock is needed on the table; a full table re-write is needed; any constraints on the column need to be re-evaluated for every row and/or may not even be applicable in the same way.

Well said Ray.

Nejlepší odpověď

Hi, 
You must be very careful because if you change the signature of the field, you will certainly lose the old values of this field. 

Luckily, when this is done, the system creates a Column where it stocks the old values. 
It calls the new column : YourField_moved0;
I suggest you to test this in your LOCAL environment  to be sure : 
1- Change the signature of the field.
2- restart the server and upgrade your Module
3- In your Logs, you will notice the server telling you that :

Table `Your_table`: column `YourField` has changed type (DB=float8, def=char), data moved to column `YourField_moved0`

4- connect to your Database and past : 
 update cfdt_case set YourField=YourField_moved0;

Tip : You can start by checkin what happens  before and after when you change the signature by pasting : 
select YourField from YourTable;

Thanks. 

Avatar
Zrušit

TIp :

If you have a field with signature Datetime and you want to change it to Date, Do not worry, you don't have to do this. The system will automatically consider the Date format only.

Ex :

Before : 09/11/2018 15:29:30

After : 09/11/2018

With no modifications.

May I know, is it available in newer version(11, 12, 13) also?