Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Code First DbMigration without nuget

How to migrate DB without nuget? It is not possible to use Visual Studio with nuget in production environment. Currently, many examples only teach us to use Visual Studio with nuget. How to use the generated DbMigration classes?

like image 873
linquize Avatar asked Jun 30 '12 04:06

linquize


People also ask

How do you do initial migration?

Run the Add-Migration InitialCreate –IgnoreChanges command in Package Manager Console. This creates an empty migration with the current model as a snapshot. Run the Update-Database command in Package Manager Console. This will apply the InitialCreate migration to the database.


1 Answers

The easiest way is:

Database.SetInitializer(
    new MigrateDatabaseToLatestVersion<MyDbContext,
                                       MyDbMigrationsConfiguration>());

This will run the migrations when initializing the DbContext.

You can also force the execution manually:

var migrator = new DbMigrator(new MyMigrationsConfiguration());
migrator.Update();

(I believe you also have to set TargetDatabase on the configuration, but you can try)

like image 57
Diego Mijelshon Avatar answered Oct 30 '22 09:10

Diego Mijelshon