diff --git a/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20250913211637_AddProperParentChildRelationBaseItemWithCascade.cs b/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20250913211637_AddProperParentChildRelationBaseItemWithCascade.cs index 77f41edad2..11c84d44c6 100644 --- a/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20250913211637_AddProperParentChildRelationBaseItemWithCascade.cs +++ b/src/Jellyfin.Database/Jellyfin.Database.Providers.Sqlite/Migrations/20250913211637_AddProperParentChildRelationBaseItemWithCascade.cs @@ -10,6 +10,28 @@ namespace Jellyfin.Server.Implementations.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.Sql(""" +DELETE FROM BaseItems + WHERE + ParentId IS NOT NULL + AND + NOT EXISTS(SELECT 1 FROM BaseItems parent WHERE ParentId = parent.Id); +DELETE FROM BaseItems + WHERE + ParentId IS NOT NULL + AND + NOT EXISTS(SELECT 1 FROM BaseItems parent WHERE ParentId = parent.Id); +DELETE FROM BaseItems + WHERE + ParentId IS NOT NULL + AND + NOT EXISTS(SELECT 1 FROM BaseItems parent WHERE ParentId = parent.Id); +DELETE FROM BaseItems + WHERE + ParentId IS NOT NULL + AND + NOT EXISTS(SELECT 1 FROM BaseItems parent WHERE ParentId = parent.Id); +"""); migrationBuilder.AddForeignKey( name: "FK_BaseItems_BaseItems_ParentId", table: "BaseItems",