39

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?

sshow
  • 8,300
  • 3
  • 49
  • 80
amiry jd
  • 25,881
  • 27
  • 106
  • 207

3 Answers3

39

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>());
OneHoopyFrood
  • 3,760
  • 2
  • 22
  • 38
Ladislav Mrnka
  • 355,666
  • 57
  • 651
  • 662
35

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

Nick Spreitzer
  • 10,008
  • 4
  • 34
  • 56
Noel
  • 1,768
  • 1
  • 19
  • 35
  • 1
    The Migrations folder where? I'm EF6 code-first and don't seem to have one anywhere. I certainly didn't make one. – Alastair Maw Oct 31 '16 at 11:49
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)

CyberFox
  • 730
  • 6
  • 23
Buzzrick
  • 773
  • 8
  • 20
  • 11
    Down vote for being so vague. Where exactly in your code did you include that command? – JBeckton Oct 06 '13 at 03:12
  • 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. – Buzzrick Oct 07 '13 at 01:26
  • 10
    `AutomaticMigrationsEnabled` property is located in /Migrations/Configuration.cs – Joseph Woodward Oct 27 '13 at 02:04