Developer forum

Forum » CMS - Standard features » Item - change field type from decimal number to text, without loosing the value of already created items

Item - change field type from decimal number to text, without loosing the value of already created items

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

Is it possible to somehow change the type of a field in an itemtype from decimal number to text, without loosing data of already created items? (we have 2.000 items, and donĀ“t want to enter all data again)

 

If i eg. have an item type field of the type decimal number, and systemname "MyField" - how can i change this to a textfield in the database, without loosing existing data?

 

/Hans


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Hans,

It is not possible to do this in the administration, but it is possible to do it directly by making changes to the database table and itemtype definition.
You can do this (at your own risk)...

  1. Create a backup - just in case ;)
  2. In SQL Server right click the ItemType_* table and select "Design". Change the column data type from float to nvarchar(max). Save changes.
  3. Find the item type definition file in /Files/System/Items. Modify the definition for the field to use System.String instead of System.Double and use Dynamicweb.Content.Items.Editors.TextEditor instead of Dynamicweb.Content.Items.Editors.DecimalEditor. Save changes.
  4. You might need to recycle the application pool in IIS to ensure that all caches are cleared.

If a warning pops up in SQL Server when trying to change the column type then you might need to uncheck the setting "Prevent saving changes that require the table to be re-created". See Save (Not Permitted) Dialog Box.

An alternative (and more safe) approach is to just create a new item field and then copy over the values from the old item field.

Best regards,
Morten

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok

Gonna have to think twice about this before i decide to get into this. In case I do, how can I get access to the SQL server on a shared hosting, not custom, Dynamicweb W&E solution?

/Hans

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

With shared hosting you don't have direct access to the SQL database. You'll have to find another solution or contact Service Desk and ask them to take a closer look at it.

/Morten

Votes for this answer: 1
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Hans

An alternative solution is to make a new field with the right type, and go to settings, database, sql firehose and do a "update table set newfield = oldfield" maybe with a convert.

BR Nicolai

Votes for this answer: 2
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok, thank you

Will look into that

/Hans

 

You must be logged in to post in the forum