Add-Migration doesn't work after upgrading from Entity Framework Core 1.1 to 2

entity-framework-core

Question

I upgraded my ASP.NET project from Entity Framework Core 1.1. to Entity Framework Core 2.

I have a class library that targets the .net framework.

I have multiple DBContext in my class library

When I run the command Add-Migration MyMigration I get

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

I then run Add-Migration MyMigration -Context MyContext

I then get

Unable to create an object of type 'MyContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

This command use to work

1
0
8/31/2017 9:03:29 AM

Popular Answer

It seems like your upgrade not only Ef,but also Asp.Net CORE. Change your Program.cs file to:

public class Program
{
    public static void Main(string[] args)
    {
        var host = BuildWebHost(args);

        host.Run();
    }

    // Tools will use this to get application services
    public static IWebHost BuildWebHost(string[] args) =>
        new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
} 
2
9/12/2017 7:41:36 AM


Related Questions





Related

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