EF Code First DbMigration without nuget

ef-code-first ef-migrations entity-framework

Question

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?

1
12
6/30/2012 4:39:03 AM

Accepted Answer

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)

12
6/30/2012 11:44:44 PM

Popular Answer

Here are the options:

  1. Use the migrate.exe command line tool that ships in our NuGet package.
  2. Use the MigrateDatabaseToLatestVersion initializer as others have described.
  3. Use the runtime API available from the DbMigrator class.


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