Using a Separate Migrations Project

You may want to store your migrations in a different project than the one containing your DbContext. You can also use this strategy to maintain multiple sets of migrations, for example, one for development and another for release-to-release upgrades.


You can view this article's sample on GitHub.


  1. Create a new class library.

  2. Add a reference to your DbContext project.

  3. Move the migrations and model snapshot files to the class library.


    If you have no existing migrations, generate one in the project containing the DbContext then move it. This is important because if the migrations project does not contain an existing migration, the Add-Migration command will be unable to find the DbContext.

  4. Configure the migrations assembly:

        options =>
                x => x.MigrationsAssembly("WebApplication1.Migrations")));
  5. Add a reference to your migrations project from the startup project.

      <ProjectReference Include="..\WebApplication1.Migrations\WebApplication1.Migrations.csproj" />

    If this causes a circular dependency, you can update the base output path of the migrations project instead:


If you did everything correctly, you should be able to add new migrations to the project.

dotnet ef migrations add NewMigration --project WebApplication1.Migrations