Enabling Migrations in EF core?

mshwf picture mshwf · Dec 1, 2017 · Viewed 19.5k times · Source

I'm getting started with EF Core 2.0, I have a console application targetting .NET 4.6.1 I have a very simple model class, and this context:

public class ContextCore : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["efCoreCon"].ConnectionString);
    }
    public DbSet<ModelC> Models { get; set; }
}

this is the connection string:

<add name="efCoreCon" connectionString="server=PC-MSHWF\SQLEXPRESS;database=efCoreDB;integrated security=true;" />

I noticed that there's no command for Enable-Migrations in ef core from the official docs

so I run Add-migration firstMigration but I got this error:

No migrations configuration type was found in the assembly 'NewConsole'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

when I tried Enable-Migrations , I got this error:

No context type was found in the assembly 'NewConsole'.

Answer

Stivi C. picture Stivi C. · Dec 1, 2017

Go to the Package Manager Console and install the needed tools with Install-Package Microsoft.EntityFrameworkCore.Tools. When it has completed try to use the command EntityFrameworkCore\Add-Migration firstMigration.