Valter
Valter

Reputation: 2899

Code First Automatic Migration

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.

Upvotes: 2

Views: 942

Answers (2)

Valter
Valter

Reputation: 2899

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

Database.SetInitializer(new NullDatabaseInitializer<DbContext>());

Upvotes: 1

Daniel Forero
Daniel Forero

Reputation: 95

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.

Upvotes: 1

Related Questions