How can I disable migration in Entity Framework 6.0

Via web.config see - https://msdn.microsoft.com/en-us/data/jj556606.aspx#Initializers

Via Code (oddly, MUCH simpler answer)

public class MyDB : DbContext
{
    public MyDB()
    {
        Database.SetInitializer<MyDB>(null);
    }
}

or in Global.asax.cs

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        // ...

        Database.SetInitializer<MyDB>(null);

        /// ...

    }
}

If you found this question hoping for a simple answer to disable migrations because you typed "Enable-Migrations" and now things aren't working the way you expected, like not running the seed method you thought it would run, then look in the solution explorer and delete the Migrations folder. That will stop the code from looking at the migrations config to find initialization code. To get the Migrations folder back, just run "Enable-Migrations" again.


You can put this inside your entityFramework section of the app.config:

<contexts>
  <context type="YourNamespace.YourDbContext, YourAssemblyName" disableDatabaseInitialization="true"/>
</contexts>

This msdn page tells all about the Entity Framework Configuration Section.


Try this:

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

UPDATE:

You can also try this:

Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists());