ASP - Core Migrate EF Core SQL DB on Startup

后端 未结 11 918
故里飘歌
故里飘歌 2020-12-01 02:32

Is it possible to have my ASP Core Web API ensure the DB is migrated to the latest migration using EF Core? I know this can be done through the command line, but I want to

11条回答
  •  北海茫月
    2020-12-01 03:22

    A note from documentation on the call to db.Database.EnsureCreated():

    Note that this API does not use migrations to create the database. In addition, the database that is created cannot be later updated using migrations. If you are targeting a relational database and using migrations, you can use the DbContext.Database.Migrate() method to ensure the database is created and all migrations are applied.

    You may just want to call db.Database.Migrate().

    Comment taken from source found above declaration here.

提交回复
热议问题