EF Core Multiple migration sets

.net-core entity-framework-core


I'm currently working on a .Net Core app using EF Core Code First Migrations. I'm jumping between Windows and OS X to do my development (Windows at home, Mac on the go) and I'm trying to figure out how I can use database migrations for SQL Server when I am on Windows and SQLite when on my Mac.

Is it possible to maintain two sets of migrations and select which set to apply (without needing to specify each migration individually)? Or would I need to create separate .Net Core applications/assemblies and specify the --assembly option for the dotnet ef database update command?

3/15/2017 8:00:49 PM

Accepted Answer

You have two options:

  1. Use two sets of Migrations
  2. Manually edit the migrations to be provider-agnostic

Multiple sets

Each set needs to be in its own assembly. To get started, generate the first migration and move it into a new project. You would configure the migrations assembly when you configured the provider.

    , x => x.MigrationsAssembly("MyApp.Migrations.SqlServer"));
//    sqliteConnectionString,
//    x => x.MigrationsAssembly("MyApp.Migrations.Sqlite"));

I have a sample that puts migrations in their own assembly that you might also want to use as a reference.


To make the migrations provider-agnostic, merge what each provider would generate. For example, the following has annotations for both SQL Server and SQLite.

    name: "People",
    columns: table => new
        Id = table.Column<int>(nullable: false)
            .Annotation("Sqlite:Autoincrement", true)
    constraints: table =>
        table.PrimaryKey("PK_People", x => x.Id);
3/16/2017 5:01:21 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow