Database migration failed: "An item with the same key has already been added. Key: Tmdb" #7726

Open
opened 2025-12-22 06:20:17 +01:00 by backuprepo · 1 comment
Owner

Originally created by @rfwatson on GitHub (Nov 9, 2025).

Description of the bug

Upgrading from 10.10 to 10.11, the migration fails with the following error. Searching Google and Github there are various mentions of problems with this upgrade but nothing which matches this specific error.

<snip>
[20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Start Moving TypedBaseItem
[20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Start Loading TypedBaseItems
[20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Loading TypedBaseItems took '00:00:00.3840873'
[20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Moving TypedBaseItem took '00:00:00.3843819'
[20:11:52] [FTL] [7] InternalCodeMigration: Error: An item with the same key has already been added. Key: Tmdb
[20:11:52] [ERR] [7] InternalCodeMigration: Migration 20250420200000_MigrateLibraryDb failed
System.ArgumentException: An item with the same key has already been added. Key: Tmdb
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Jellyfin.Server.Implementations.Item.BaseItemRepository.Map(BaseItemEntity entity, BaseItem dto, IServerApplicationHost appHost, ILogger logger)
   at Jellyfin.Server.Implementations.Item.BaseItemRepository.DeserializeBaseItem(BaseItemEntity baseItemEntity, ILogger logger, IServerApplicationHost appHost, Boolean skipDeserialization)
   at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.GetItem(SqliteDataReader reader)
   at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.Perform()
   at Jellyfin.Server.Migrations.Stages.CodeMigration.Perform(IServiceProvider serviceProvider, IStartupLogger logger, CancellationToken cancellationToken)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.InternalCodeMigration.PerformAsync(IStartupLogger logger)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider)
[20:11:52] [INF] [7] InternalCodeMigration: Attempt to rollback librarydb.
[20:11:52] [INF] [7] InternalCodeMigration: Attempt to rollback JellyfinDb.
[20:11:52] [FTL] [7] Main: Error while starting server
System.ArgumentException: An item with the same key has already been added. Key: Tmdb
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Jellyfin.Server.Implementations.Item.BaseItemRepository.Map(BaseItemEntity entity, BaseItem dto, IServerApplicationHost appHost, ILogger logger)
   at Jellyfin.Server.Implementations.Item.BaseItemRepository.DeserializeBaseItem(BaseItemEntity baseItemEntity, ILogger logger, IServerApplicationHost appHost, Boolean skipDeserialization)
   at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.GetItem(SqliteDataReader reader)
   at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.Perform()
   at Jellyfin.Server.Migrations.Stages.CodeMigration.Perform(IServiceProvider serviceProvider, IStartupLogger logger, CancellationToken cancellationToken)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.InternalCodeMigration.PerformAsync(IStartupLogger logger)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider)
   at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider)
   at Jellyfin.Server.Program.StartServer(IServerApplicationPaths appPaths, StartupOptions options, IConfiguration startupConfig)
[20:12:22] [ERR] [18] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0681ms with message 'Server is could not complete startup. Check logs.'
[20:12:52] [ERR] [21] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0056ms with message 'Server is could not complete startup. Check logs.'
[20:13:22] [ERR] [24] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0036ms with message 'Server is could not complete startup. Check logs.'
[20:13:52] [ERR] [27] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0039ms with message 'Server is could not complete startup. Check logs.'
[20:14:22] [ERR] [29] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0042ms with message 'Server is could not complete startup. Check logs.'
[20:14:52] [ERR] [32] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0062ms with message 'Server is could not complete startup. Check logs.'
[20:15:22] [ERR] [35] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0037ms with message 'Server is could not complete startup. Check logs.'
[20:15:52] [ERR] [37] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0048ms with message 'Server is could not complete startup. Check logs.'
[20:16:22] [ERR] [40] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0038ms with message 'Server is could not complete startup. Check logs.'
[20:16:52] [ERR] [43] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0039ms with message 'Server is could not complete startup. Check logs.'
[20:17:22] [ERR] [46] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0036ms with message 'Server is could not complete startup. Check logs.'
[20:17:52] [ERR] [48] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0034ms with message 'Server is could not complete startup. Check logs.'
[20:18:22] [ERR] [53] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0038ms with message 'Server is could not complete startup. Check logs.'

Reproduction steps

Switch Docker image from 10.10.x to 10.11 latest.

What is the current bug behavior?

Unable to start server.

What is the expected correct behavior?

Be able to start the server.

Jellyfin Server version

10.11.0+

Specify commit id

No response

Specify unstable release number

No response

Specify version number

No response

Specify the build version

Unknown, can't open dashboard

Environment

- OS: Truenas Scale
- Linux Kernel: 6.12
- Virtualization: Docker
- Clients: -
- Browser: - 
- FFmpeg Version: -
- Playback Method:
- Hardware Acceleration:
- GPU Model:
- Plugins:
- Reverse Proxy:
- Base URL:
- Networking:
- Jellyfin Data Storage:
- Media Storage:
- External Integrations:

Jellyfin logs

See other section.

FFmpeg logs


Client / Browser logs

No response

Relevant screenshots or videos

No response

Additional information

No response

Originally created by @rfwatson on GitHub (Nov 9, 2025). ### Description of the bug Upgrading from 10.10 to 10.11, the migration fails with the following error. Searching Google and Github there are various mentions of problems with this upgrade but nothing which matches this specific error. ``` <snip> [20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Start Moving TypedBaseItem [20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Start Loading TypedBaseItems [20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Loading TypedBaseItems took '00:00:00.3840873' [20:11:52] [INF] [7] Jellyfin.Server.Migrations.Routines.MigrateLibraryDb: Moving TypedBaseItem took '00:00:00.3843819' [20:11:52] [FTL] [7] InternalCodeMigration: Error: An item with the same key has already been added. Key: Tmdb [20:11:52] [ERR] [7] InternalCodeMigration: Migration 20250420200000_MigrateLibraryDb failed System.ArgumentException: An item with the same key has already been added. Key: Tmdb at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at Jellyfin.Server.Implementations.Item.BaseItemRepository.Map(BaseItemEntity entity, BaseItem dto, IServerApplicationHost appHost, ILogger logger) at Jellyfin.Server.Implementations.Item.BaseItemRepository.DeserializeBaseItem(BaseItemEntity baseItemEntity, ILogger logger, IServerApplicationHost appHost, Boolean skipDeserialization) at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.GetItem(SqliteDataReader reader) at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.Perform() at Jellyfin.Server.Migrations.Stages.CodeMigration.Perform(IServiceProvider serviceProvider, IStartupLogger logger, CancellationToken cancellationToken) at Jellyfin.Server.Migrations.JellyfinMigrationService.InternalCodeMigration.PerformAsync(IStartupLogger logger) at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider) [20:11:52] [INF] [7] InternalCodeMigration: Attempt to rollback librarydb. [20:11:52] [INF] [7] InternalCodeMigration: Attempt to rollback JellyfinDb. [20:11:52] [FTL] [7] Main: Error while starting server System.ArgumentException: An item with the same key has already been added. Key: Tmdb at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at Jellyfin.Server.Implementations.Item.BaseItemRepository.Map(BaseItemEntity entity, BaseItem dto, IServerApplicationHost appHost, ILogger logger) at Jellyfin.Server.Implementations.Item.BaseItemRepository.DeserializeBaseItem(BaseItemEntity baseItemEntity, ILogger logger, IServerApplicationHost appHost, Boolean skipDeserialization) at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.GetItem(SqliteDataReader reader) at Jellyfin.Server.Migrations.Routines.MigrateLibraryDb.Perform() at Jellyfin.Server.Migrations.Stages.CodeMigration.Perform(IServiceProvider serviceProvider, IStartupLogger logger, CancellationToken cancellationToken) at Jellyfin.Server.Migrations.JellyfinMigrationService.InternalCodeMigration.PerformAsync(IStartupLogger logger) at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider) at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider) at Jellyfin.Server.Migrations.JellyfinMigrationService.MigrateStepAsync(JellyfinMigrationStageTypes stage, IServiceProvider serviceProvider) at Jellyfin.Server.Program.StartServer(IServerApplicationPaths appPaths, StartupOptions options, IConfiguration startupConfig) [20:12:22] [ERR] [18] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0681ms with message 'Server is could not complete startup. Check logs.' [20:12:52] [ERR] [21] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0056ms with message 'Server is could not complete startup. Check logs.' [20:13:22] [ERR] [24] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0036ms with message 'Server is could not complete startup. Check logs.' [20:13:52] [ERR] [27] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0039ms with message 'Server is could not complete startup. Check logs.' [20:14:22] [ERR] [29] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0042ms with message 'Server is could not complete startup. Check logs.' [20:14:52] [ERR] [32] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0062ms with message 'Server is could not complete startup. Check logs.' [20:15:22] [ERR] [35] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0037ms with message 'Server is could not complete startup. Check logs.' [20:15:52] [ERR] [37] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0048ms with message 'Server is could not complete startup. Check logs.' [20:16:22] [ERR] [40] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0038ms with message 'Server is could not complete startup. Check logs.' [20:16:52] [ERR] [43] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0039ms with message 'Server is could not complete startup. Check logs.' [20:17:22] [ERR] [46] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0036ms with message 'Server is could not complete startup. Check logs.' [20:17:52] [ERR] [48] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0034ms with message 'Server is could not complete startup. Check logs.' [20:18:22] [ERR] [53] Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService: Health check StartupCheck with status Unhealthy completed after 0.0038ms with message 'Server is could not complete startup. Check logs.' ``` ### Reproduction steps Switch Docker image from 10.10.x to 10.11 latest. ### What is the current _bug_ behavior? Unable to start server. ### What is the expected _correct_ behavior? Be able to start the server. ### Jellyfin Server version 10.11.0+ ### Specify commit id _No response_ ### Specify unstable release number _No response_ ### Specify version number _No response_ ### Specify the build version Unknown, can't open dashboard ### Environment ```markdown - OS: Truenas Scale - Linux Kernel: 6.12 - Virtualization: Docker - Clients: - - Browser: - - FFmpeg Version: - - Playback Method: - Hardware Acceleration: - GPU Model: - Plugins: - Reverse Proxy: - Base URL: - Networking: - Jellyfin Data Storage: - Media Storage: - External Integrations: ``` ### Jellyfin logs ```shell See other section. ``` ### FFmpeg logs ```shell ``` ### Client / Browser logs _No response_ ### Relevant screenshots or videos _No response_ ### Additional information _No response_
backuprepo added the
bug
label 2025-12-22 06:20:17 +01:00
Author
Owner

@martimarkov commented on GitHub (Nov 17, 2025):

@rfwatson This can be manually fixed by finding all entries which for some reason have multiple ProviderIds:

SELECT *
FROM TypedBaseItems
WHERE 
  (LENGTH(ProviderIds) - LENGTH(REPLACE(ProviderIds, 'XXXXX=', ''))) / LENGTH('XXXXX=') > 1;

where XXXXX is either Tmdb or Imdb or another provider which shows in the error log.

@martimarkov commented on GitHub (Nov 17, 2025): @rfwatson This can be manually fixed by finding all entries which for some reason have multiple `ProviderIds`: ``` SELECT * FROM TypedBaseItems WHERE (LENGTH(ProviderIds) - LENGTH(REPLACE(ProviderIds, 'XXXXX=', ''))) / LENGTH('XXXXX=') > 1; ``` where `XXXXX` is either `Tmdb` or `Imdb` or another provider which shows in the error log.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/jellyfin#7726
No description provided.