How to enable automatic migration in production

c# entity-framework-6

Question

I know the basics of enabling automatic migration using this link.

Could anyone tell what is the best way to enable automatic migration in production without any hassle and how to do the automatic migration in scenarios where the connection string is provided during runtime?

1
1
8/17/2018 6:00:25 AM

Popular Answer

I have this in place for my production platform, note that the command is only executed when the build is done in something other then debug mode.

#if !DEBUG
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<VerbekeContext, Default.Migrations.Configuration>());
#endif

this is added in my global.asax of an MVC project in the startup function, so if you have any other application you should execute this @ startup

Or you could set the AutomaticMigrationsEnabled to true in the configuration.cs in the migrations folder. If you add the debug switch, set it to false in debug and true in other build modes.

namespace Default.Migrations
{
using System.Data.Entity.Migrations;

public sealed class Configuration : DbMigrationsConfiguration<Context>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
    }

    protected override void Seed(Context context)
    {
       ///
    }
}
}
0
11/24/2016 2:05:23 PM


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