Issue

Sometimes, it is necessary to move your K2 database to a different SQL instance. This usually requires you to recreate the K2 master keys for SQL encryption. 

Symptoms

In this case, the K2 database was moved prior to upgrading from K2 blackpearl 4.6.11 to 4.7.

The following error is logged in the installer trace file:

Could not recreate key: System.Data.SqlClient.SqlException (0x80131904): Error 515, Level 16, State 2, Procedure -, Line 6 Cannot insert the value NULL into column 'AccessToken', table 'K2.Authorization.OAuthToken'; column does not allow nulls. UPDATE fails.
 

This error can appear whenever the K2 master keys are manually recreated on a K2 database that was moved, or after server relocation.

Resolution

If the issue occurred during an upgrade:

1. Restore to the pre-upgrade version of K2.

2. Run the following commands on the ‘K2’ database (replace with your K2 database name if different):

delete from [K2].[Authorization].[OAuthAppOnlyToken] delete from [K2].[Authorization].[OAuthToken] delete from [K2].[Authorization].[OAuthIdentity]

3. Rerun the Upgrade/Update.

If this occurred outside the context of an upgrade, you can skip step 1, and rerun the last-applied update.