Code First Automatic Migration

c# entity-framework entity-framework-6

Question

The current project I am working on, I am telling Entity Framework to do nothing by setting SetInitializer with params null:

public EfDbContext()
{
   Database.SetInitializer<EfDbContext>(null); //new NullDatabaseInitializer<EfDbContext>());
}

I have a script that creates a few table. When I running the script, it is creating the dbo.__MigrationHistory in the DB.

How can I disable migration, I thought the above code would disable that.

Am I missing something? I also don't have migration enabled and any configuration files for migration.

I am using EF 6.1.3.

1
2
8/8/2017 3:06:57 PM

Accepted Answer

I fixed the issue by adding the following code into the Application_Start() in Global.asax:

Database.SetInitializer(new NullDatabaseInitializer<DbContext>());
1
8/11/2017 1:31:14 PM

Popular Answer

In your migrations folder there is a file called Configuration, in the constructor try something like this:

public Configuration()
{
     AutomaticMigrationsEnabled = false;
}

The ugly but easy way to disable the migrations at all regardless the configuration is deleting the table dbo.__MigrationHistory.



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