{"title":"AppSourceCop Error AS0010","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/appsourcecop-as0010/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0010, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0010","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"The primary key must not be deleted because this will break upgrade of existing installations.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"AppSourceCop Error AS0010","slug":"appsourcecop-error-as0010","at":0,"chars":3500},{"level":2,"title":"Description","slug":"description","at":53,"chars":680},{"level":2,"title":"How to fix this diagnostic?","slug":"how-to-fix-this-diagnostic","at":733,"chars":164},{"level":2,"title":"Code examples triggering the rule","slug":"code-examples-triggering-the-rule","at":897,"chars":2456},{"level":3,"title":"Example 1 - Renaming the primary key","slug":"example-1---renaming-the-primary-key","at":934,"chars":719},{"level":3,"title":"Example 2 - Explicitly adding a primary key","slug":"example-2---explicitly-adding-a-primary-key","at":1653,"chars":977},{"level":3,"title":"Example 3 - Removing the primary key","slug":"example-3---removing-the-primary-key","at":2630,"chars":723},{"level":2,"title":"Related information","slug":"related-information","at":3353,"chars":147}],"text":"# AppSourceCop Error AS0010\nKeys must not be deleted\n## Description\nThe primary key must not be deleted because this will break upgrade of existing installations.\nIt is not allowed to rename the primary key because this will break upgrade of existing installations. Note that a primary key is always automatically generated for your table even if you do not specify any keys in your AL code. Removing the primary key will then be seen as a rename by the AppSourceCop analyzer. For more information on table keys, see ../devenv-table-keys.\n> NOTE\n> This rule validates tables independently of their Accessibility or ObsoleteState, because tables are always used when synchronizing the schema defined in the extension to the database.\n## How to fix this diagnostic?\nTo fix this diagnostic, you must rename the primary key or add it back so that it matches its definition in your baseline extension.\n## Code examples triggering the rule\n### Example 1 - Renaming the primary key\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n    }\n}\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n\n    keys\n    {\n        key(MyPK; MyIntegerField) { }\n    }\n}\n```\nIn version 2.0, the key PK has been renamed to MyPK. This change is not allowed by the synchronization engine.\n> NOTE\n> The validation of the primary key's name by the synchronization engine is case-sensitive. Changing the casing of the primary key's name is then considered a breaking change.\n### Example 2 - Explicitly adding a primary key\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n}\n```\nIn version 1.0 of the extension, no primary key is explictly defined in AL code. By default, the first field by ID will be used as primary key. The primary key is then similar to:\n```al\nkey(MyIntegerField; MyIntegerField) { }\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n    }\n}\n```\nIn version 2.0 of the extension, a key named PK has been introduced and will act as the primary key for the table. This is not allowed because the primary key in version 1.0 was named MyIntegerField.\n> NOTE\n> If the key introduced was named MyIntegerField, the change would be allowed because it would match the default name given to the primary key in the baseline version.\n### Example 3 - Removing the primary key\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n    }\n}\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n    }\n}\n```\nIn version 2.0 of the extension, no primary key is explictly defined in AL code. By default, the first field by ID will be used as primary key. The primary key is then similar to:\n```al\nkey(MyIntegerField; MyIntegerField) { }\n```\nThis change is not allowed because the primary key was named PK in the baseline extension while it is now named MyIntegerField.\n## Related information\nAppSourceCop Analyzer<appsourcecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}