Error with upgrade codeunit when changing table's PK length

red49red49 Member Posts: 1
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.

Best Answer

Answers

  • gerdhuebnergerdhuebner Member Posts: 155
    Never use the "Forced" method in this case. Even if all primary field values have a length, which is not greater than the new field length, all records will be deleted!
  • rsaritzkyrsaritzky Member Posts: 469
    I'm reading about upgrade codeunits. There is a whitepaper from MS that walks through the process:
    go.microsoft.com/fwlink/?LinkID=509977

    This has a scenario of deleting fields in a table. Once you create the upgrade codeunit, you can open the original table and delete the fields. The copy to the upgrade table will happen automatically.

    It then says "The same would also happen if instead of deleting the fields in the table directly you would import a FOB file with another version of the Vehicle table where these fields are absent."

    So what about the scenario where you have built the upgrade codeunit and upgrade table and have a new table definition with fields removed, and you are moving this to a copy of the database, e.g. from Development to Test or Test to Production?

    Does this mean you need to import the Upgrade codeunit and upgrade table FOB's first. Then, once they are in the database, you can import the new table definition?

    Ron
    Ron
Sign In or Register to comment.