Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply migrations from code (EF Core)

Here is some working EF6 migration code:

Database.SetInitializer<CmContext>(null);
var settings = new MigrationsConfiguration();
var migrator = new DbMigrator(settings);
migrator.Update();

What is the equivalent using EF Core?

like image 987
Dmitry L Avatar asked Jul 29 '15 20:07

Dmitry L


People also ask

How do I run down EF core migration?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.


1 Answers

In beta 7 and on, use:

using Microsoft.Data.Entity;

...

context.Database.Migrate();
like image 131
ErikEJ Avatar answered Oct 07 '22 02:10

ErikEJ