Search code examples
microsoft-dynamicsnavisiondynamics-navdynamics-nav-2016

Error with upgrade codeunit when changing table's PK length


I have table A-Z. Table A has PK of ID, and all other tables has fields that relates to TableA's ID.

I'm being tasked to do code cleanup, and I need to change the TableA's ID from length 30 to 20. I have done for other table B-Z, together with the upgrade codeunit. But when I try to change for TableA, I get this error:

"The are changes related to the following primary key that can cause data loss in the new table. The changes cannot be handled because the TableUpgradeMode of the TableSyncSetup type function for the changed table is set to Copy, which does not copy data to the new table. To fix this issue, you must change the TableUpgradeMode option to Move, then add C/AL code to an Upgrade type function to handle new table data."

What does the error mean? Do I need to change TableA's upgrade codeunit from TableSyncSetup.Mode::Copy to ::Move? Any guidance?

I'm using Dynamics NAV 2016.


Solution

  • Yes, you have to change the mode to Move but you also have to create a new table which holds the data temporarily from the fields where you've reduced the field length. You also have to handle the possible data truncation issue because of the reduced field length.

    But I would do this in a different way (the old way from the Upgrade Toolkits): - Create a new table with the same field length (30), copy the field contents and clear the fields (using a codeunit) - Change the field lengths and but choose Force when NAV is asking about the Sync Mode (because you know that there is no data in those fields - SQL can drop and recreate the columns) - Using a second codeunit copy the data back into the reduced fields - handle the truncation

    I hope it helps