2

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I don't have any migration configuration. I don't have a migration folder. Every time i delete the dbo.__MigrationHistory, when I run the script that creates the table, the dbo.__MigrationHistory gets created again
ok, go to your package manager console and enter this command: add-migration initialSchema This will allow you to manage the migrations manually, and it will creates this folder and the configuration for you.
Why is EF creating dbo.__MigrationHistory table if it is not enabled? Is it default behavior?
yes it is, the table is not only for automatic migrations, it is use for all the migrations regardless if you are applying it by hand or automatic, this table is use to calculate what changes the migration needs to do in the database based in the information of the table and what is new in the code.
Is there any way to prevent EF from creating migration history table in the DB?
|
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.