Search code examples
entity-framework-coreef-code-firstentity-framework-migrations

Run an EF core migration without a transaction?


I've got a Postgres database where I use the Postgres type of Enum. The issue I'm having is that when I add an enum via a migration, I get an error stating that it can't be ran in a transaction. This would mean that if I ever had to recreate a database it would always fail because that migration would never run correctly.

So my question is, is there a way of turning off transactions in entity frameworks migrations? Or if you can, whether you would want to?

For clarity, here's a link to the question I've got about the specific failing migration.

ALTER TYPE ... ADD cannot run inside a transaction block - Entity Framework

Thanks


Solution

  • I found that there's an overload for the .Sql command where you can specify true to suppress a transaction.

    migrationBuilder.Sql("your sql statement", true);