Boppity Bop
Boppity Bop

Reputation: 10463

Upgrading ASP.NET Core 5.0 IdentityServer4 to 6.0 error - no such table: Keys

After upgrading ASP.NET Core 5.0 with IdentityServer4 to 6.0 error - no such table: Keys

14:50:02.0033786|Failed executing DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "k"."Id", "k"."Algorithm", "k"."Created", "k"."Data", "k"."DataProtected", "k"."IsX509Certificate", "k"."Use", "k"."Version"
FROM "Keys" AS "k"
WHERE "k"."Use" = 'signing'
14:50:02.0179085|An exception occurred while iterating over the results of a query for context type 'xx.com.Data.AppDbContext'.
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: Keys'.

I cant find any doc on migration from .net 5 to 6 for IdentityServer

EDIT when you upgrade ID4 from .NET Core 5 to 6 it becomes Duende Server. There is no ID4 for .NET 6..

Upvotes: 2

Views: 2561

Answers (3)

Boppity Bop
Boppity Bop

Reputation: 10463

Quick way to resolve this (sqlite):

CREATE TABLE Keys (
    Id                TEXT    NOT NULL
                              CONSTRAINT PK_Keys PRIMARY KEY,
    Version           INTEGER NOT NULL,
    Created           TEXT    NOT NULL,
    Use               TEXT,
    Algorithm         TEXT    NOT NULL,
    IsX509Certificate INTEGER NOT NULL,
    DataProtected     INTEGER NOT NULL,
    Data              TEXT    NOT NULL
);

CREATE INDEX IX_Keys_Use ON Keys (
    "Use"
);

CREATE INDEX sqlite_autoindex_Keys_1 ON Keys (
    Id COLLATE BINARY
);

Upvotes: 1

mixlplix
mixlplix

Reputation: 11

Here's the correct schema for the Keys table

CREATE TABLE Keys (
    Id                nvarchar(450)    NOT NULL CONSTRAINT PK_Keys PRIMARY KEY,
    Version           INTEGER NOT NULL,
    Created           datetime2    NOT NULL,
    [Use]               nvarchar(450),
    Algorithm         nvarchar(100)    NOT NULL,
    IsX509Certificate INTEGER NOT NULL,
    DataProtected     INTEGER NOT NULL,
    Data              nvarchar(Max)    NOT NULL
);

CREATE INDEX IX_Keys_Use ON Keys (
    [Use]
);

CREATE INDEX sqlite_autoindex_Keys_1 ON Keys (
    Id 
);

Upvotes: 1

Iván Almeida
Iván Almeida

Reputation: 41

Disable the management of certificates via database (Table 'Keys' doesn't exists). You can stay loading certificates from any other available source.

services.AddIdentityServer(options => {
    options.KeyManagement.Enabled = false;
})

Upvotes: 4

Related Questions