更改 table 的 PK 长度时升级代码单元出错

Error with upgrade codeunit when changing table's PK length

我有 table A-Z。 Table A 有 ID 的 PK,所有其他 tables 都有与 TableA 的 ID 相关的字段。

我的任务是清理代码,我需要将 TableA 的 ID 从长度 30 更改为 20。我已经为其他 table B-Z 完成了,连同升级代码单元。但是当我尝试更改为 TableA 时,出现此错误:

"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."

错误是什么意思?我是否需要将 TableA 的升级代码单元从 TableSyncSetup.Mode::Copy 更改为 ::Move?有什么指导吗?

我正在使用 Dynamics NAV 2016。

是的,您必须将模式更改为“移动”,但您还必须创建一个新的 table 来临时保存您已减少字​​段长度的字段中的数据。由于字段长度减少,您还必须处理可能的数据截断问题。

但我会用不同的方式(升级工具包中的旧方式): - 创建一个具有相同字段长度 (30) 的新 table,复制字段内容并清除字段(使用代码单元) - 更改字段长度,但在 NAV 询问同步模式时选择强制(因为您知道这些字段中没有数据 - SQL 可以删除并重新创建列) - 使用第二个代码单元将数据复制回减少的字段 - 处理截断

希望对你有帮助