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?
How to disable migration in Entity Framework 4.3.1?
Asked Answered
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>());
new CreateDatabaseIfNotExists<YourContentType>() –
Moisture
What class/file does this actually go in? –
Albescent
@jep, the entry point for your application. E.g.
global.asax.cs
or Program.Main
. –
Lundell This does not work in EF6. MSFT turned it off because of conflicts between the migration and the intitializers. See entityframework.codeplex.com/workitem/1689 –
Biracial
How to make it ALWAYS rebuild from scratch even if there was no changes? I tried many things to do so. –
Duppy
In aspnet.core 2.0 I get the error: 'DatabaseFacade' does not contain a defininition for 'SetInitializer'. –
Bullyboy
Deleting the Migrations
folder has worked for me. I don't get any errors, it puts me back to where I started.
The Migrations folder where? I'm EF6 code-first and don't seem to have one anywhere. I certainly didn't make one. –
Gezira
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)
Down vote for being so vague. Where exactly in your code did you include that command? –
Knit
hmmm... good question JBeckton. it's been a while since I've looked at that code, and I don't think that I still have access to it anywhere. I remember that it was in the Entity Framework setup section of my code. Not very helpful, I know, so my apologies on that. –
Indefensible
AutomaticMigrationsEnabled
property is located in /Migrations/Configuration.cs –
Zollverein © 2022 - 2024 — McMap. All rights reserved.
Database.SetInitializer<YourContextType>(null)
to startup of your application. – Gleaning