I have a metafield that is type decimal. I want to change it to double. I tried to remove that field from code and then restart the app but I still see the meta field is still there and there's no option in commerce manager to unlink it or remove it. The reason I want to do this is to update it's type. But just updating the data type in code causes the site to crash when loading.
Any help would be appreciated.
Commerce version: 13.21 (build: 0)
Do you have any data that you want to migrate? If yes it will be very tricky. But if no you once you removed the property you should be able to unlink it from the metaclass and then delete it using Commerce Manager.
There is existing data, but we can run a job to repopulate that data. It's the product data, so would I have to delete the product data, restart the site without the property in the code, and then unlink and delete the property, then add the property back in with the new data type, restart the site again, and then repopulate the data?
I think there is no option in Episerver commerce UI to update datatype directly but you can change the datatype with help of the database approach:
SELECT COLUMN_NAME AS 'ColumnName' ,TABLE_NAME AS 'TableName'FROM INFORMATION_SCHEMA.COLUMNSWHERE COLUMN_NAME LIKE '%MyColumnName%'ORDER BY TableName ,ColumnName;
ALTER TABLE [Table 1]DROP COLUMN MyColumnName
ALTER TABLE [Table 2]DROP COLUMN MyColumnName
DECLARE @MetaFieldId INT
SELECT @MetaFieldId=MetaFieldId FROM MetaField WHERE Name='MyColumnName'DELETE FROM MetaClassMetaFieldRelation WHERE MetaFieldId=@MetaFieldId
DELETE FROM MetaField WHERE Name='MyColumnName
Note: FYI Episerver does not recommend the database approach.
@Brian W (Whereoware) Yes, basically that.
I Support Quan's answer and in any CMS it is not a good idea to directly update the table with queries.
But sometimes you can not lose data. If you delete and re-create column then you will lose data.
If I remember correctly double is a float data type in SQL. So according to SQL, you can convert decimal to float using the following query. (Remember first you need to change type in code. It will crash the website. Then you need to change in DB and restart it)
ALTER TABLE TableNameALTER COLUMN ColumnName float;