ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

前端 未结 7 771
Happy的楠姐
Happy的楠姐 2021-01-31 04:02

I can use package manager to run \'update-database -verbose\' locally.

Probably a stupid question but I can\'t find it online - once my website is deployed - how can I r

7条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 04:14

    just to give everyone the simple answer.

    This is the "Update-Database" In your Migrations folder, Configuration.cs:

        internal sealed class Configuration : DbMigrationsConfiguration
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true; // Update-Data -Force (deletes columns etc)
        }
    

    And to "Enable migrations" in the first place on a remote server, add this to your Global.asax.cs file:

            protected void Application_Start()
        {
            ....
            System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion());
    

提交回复
热议问题