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,820
  • 4
  • 51
  • 82
amiry jd
  • 27,021
  • 30
  • 116
  • 215

3 Answers3

40

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,829
  • 3
  • 24
  • 39
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
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,242
  • 4
  • 35
  • 58
Noel
  • 1,968
  • 3
  • 20
  • 38
  • 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
4

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
  • 780
  • 6
  • 24
Buzzrick
  • 823
  • 9
  • 21
  • 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