How to Troubleshoot Issue : The Given Key 'x' Was Not Present in the Dictionary

How to Troubleshoot Issue : The Given Key 'x' Was Not Present in the Dictionary during Orchestrator upgrade?

When trying to perform the upgrade, getting error as : System.Exception: Error:1, Message: An error occurred while migrating Orchestrator data. The given key 'x' was not present in the dictionary.

This issue comes when there is/are any entries which are deleted from database, directly mostly due to dbo.Tenants table.

Identify the tenantsID from database, as these tenant ids are being referenced in various other tables, due to which this issue is being caused.
 

Troubleshooting Steps:

Note that the following tables still have dependencies

  • Users
  • MessageTemplates
  • UserLogins
  • Robots
  • Roles
  • Settings

To correct it, create a new tenant to dump the remaining entities and run the following for each table below -

UPDATE [dbo].[<TABLENAME>]

SET TenantId = <NEWTENANTIDVALUE>

WHERE [dbo].[TABLENAME].TenantId NOT IN (

SELECT Id

FROM [dbo].[Tenants]

)

 

TABLENAME : 

Users

MessageTemplates

UserLogins

Robots

Roles

And the following Delete:

DELETE

FROM [dbo].[Settings]

WHERE [dbo].[Settings].TenantId NOT IN (

SELECT Id

FROM [dbo].[Tenants]

)

 

Note : A DB back-up should be performed before doing the above operations .