Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Migrations in EF core?

Tags:

c#

ef-core-2.0

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'.

like image 461
mshwf Avatar asked Dec 01 '17 17:12

mshwf


People also ask

What is migration in EF core?

Entity Framework Core uses this table in the database to keep track of which migrations have already been applied to the database. This ensures that that Database. Migrate() call, or alternatively, the Update-Database call from the command line doesn't try to execute the same migrations over and over again.


1 Answers

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.

like image 161
Stivi C. Avatar answered Sep 18 '22 00:09

Stivi C.