0

Is there a way similar to Database.EncureCreated() method to ensure all migrations were executed from the app?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Rico
  • 362
  • 1
  • 4
  • 18
  • [db.Database.Migrate();](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationaldatabasefacadeextensions.migrate?view=efcore-3.1#Microsoft_EntityFrameworkCore_RelationalDatabaseFacadeExtensions_Migrate_Microsoft_EntityFrameworkCore_Infrastructure_DatabaseFacade_) ? – Panagiotis Kanavos Sep 30 '20 at 11:24
  • Does this answer your question? [ASP - Core Migrate EF Core SQL DB on Startup](https://stackoverflow.com/questions/37780136/asp-core-migrate-ef-core-sql-db-on-startup) – Panagiotis Kanavos Sep 30 '20 at 11:25
  • Check the following link to use the `context.Database.Migrate()` or `context.Database.EnsureCreated()` method: [auto create database in Entity Framework Core](https://stackoverflow.com/questions/42355481/auto-create-database-in-entity-framework-core) and [EF Core Seeding](https://devblogs.microsoft.com/dotnet/implementing-seeding-custom-conventions-and-interceptors-in-ef-core-1-0/). – Zhi Lv Oct 01 '20 at 06:01

1 Answers1

1

You can use Database.Migrate() - REF

From the article:

Applies any pending migrations for the context to the database. Will create the database if it does not already exist.

Note that Database.Migrate() is mutually exclusive with Database.EnsureCreated()

MultiValidation
  • 823
  • 7
  • 21