Skip to content

efcore9: Migration with .Sql that suppresses a transaction logs an error even though it works #35133

@ChristophHornung

Description

@ChristophHornung

When switching to efcore9 existing migrations that include a .Sql(..., suppressTransaction: true) will generate an error in the log even though they work.
The what is new documentation states this should only issues a warning.

Include your code

I uploaded a minimal reproduction here.

Include verbose output

The log outputs the fail message but also shows that the SQL is executed correctly.

info: Microsoft.EntityFrameworkCore.Migrations[20402]
      Applying migration '20241118110903_NonTransactable'.
fail: Microsoft.EntityFrameworkCore.Migrations[20410]
      The migration operation 'UPDATE Posts SET NewPostId = PostId+1
      ' from migration 'NonTransactable' cannot be executed in a transaction. If the app is terminated or an unrecoverable error occurs while this operation is being executed then the migration will be left in a partially applied state and would need to be reverted manually before it can be applied again. Create a separate migration that contains just this operation.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      ALTER TABLE "Posts" ADD "NewPostId" INTEGER NOT NULL DEFAULT 0;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      UPDATE Posts SET NewPostId = PostId+1
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
      VALUES ('20241118110903_NonTransactable', '9.0.0');

Include provider and version information

EF Core version: no error log on 8, but error logged on 9
Database provider: tested with SQL and SQLite
Target framework: .NET8 and .NET9

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions