How to disable migration in Entity Framework 4.3.1

2020-01-28 05:02发布

问题:

Is there any way to disable migration in Entity Framework 4.3.1? I removed the migrations folder from the project and the generated tables in my database, but it doesn't work! How can you remove the migration?

回答1:

If you don't want to use migrations but in the same time you want EF to create database for you, you just need to set correct database initializer:

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


回答2:

Deleting the Migrations folder has worked for me. I don't get any errors, it puts me back to where I started.



回答3:

The way that I got around this was to make sure that I turned off Automatic Migrations in my code:

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

and then I deleted the _MigrationHistory table from the database (this is usually created as a system table if you can't find it)