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?
            Asked
            
        
        
            Active
            
        
            Viewed 6.0k times
        
    39
            
            
        - 
                    1What do you mean by *it not works*? – Ladislav Mrnka Mar 14 '12 at 14:25
 - 
                    I mean when I delete these file and table, I ecpect to migration disabled, but it is enable yet. when I run the project it occurs an error about migration – amiry jd Mar 14 '12 at 14:27
 - 
                    12Try to add `Database.SetInitializer
(null)` to startup of your application. – Ladislav Mrnka Mar 14 '12 at 14:29 - 
                    It works. Thank you. But now, how can I create database with ef? – amiry jd Mar 14 '12 at 18:53
 - 
                    For EF6 see [How can I disable migration in Entity Framework 6.0](http://stackoverflow.com/q/18667172) – Michael Freidgeim Sep 07 '16 at 02:26
 
3 Answers
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
 
- 
                    9
 - 
                    2
 - 
                    1@jep, the entry point for your application. E.g. `global.asax.cs` or `Program.Main`. – MEMark Mar 04 '14 at 18:18
 - 
                    4This does not work in EF6. MSFT turned it off because of conflicts between the migration and the intitializers. See http://entityframework.codeplex.com/workitem/1689 – Alex Edelstein Mar 27 '14 at 23:25
 - 
                    How to make it ALWAYS rebuild from scratch even if there was no changes? I tried many things to do so. – Yoda Jul 28 '14 at 19:03
 - 
                    In aspnet.core 2.0 I get the error: 'DatabaseFacade' does not contain a defininition for 'SetInitializer'. – alexb Sep 13 '17 at 23:38
 
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
 
- 
                    1The 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)
- 
                    11Down 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