AutomaticMigrationDataLossAllowed not working

c# entity-framework

Question

I am having a scenario where the AutomaticMigrationDataLossAllowed property of my Configuration class is not working in Entity Framework 6.

I set both the required properties to true, but yet I receive an update exception which states that potential data loss could occur. Ironically, it advices me to set the properties to true that I have already set to true.

Here's how I instantiate my model container (context).

Database.SetInitializer(new ModelInitializer());
Entities = new ModelContainer();

Here's the relevant part of my ModelInitializer class.

internal class ModelInitializer : IDatabaseInitializer<ModelContainer>
{

    private static bool _usedBefore;

    public void InitializeDatabase(ModelContainer context)
    {

        ...

        var migrateInitializer = new MigrateDatabaseToLatestVersion<ModelContainer, Configuration>();
        migrateInitializer.InitializeDatabase(context);
    }
}

And finally, here's my Configuration class.

internal sealed class Configuration : DbMigrationsConfiguration<ModelContainer>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;
    }

    protected override void Seed(ModelContainer context)
    {

    }
}

My ModelContainer class (the context) basically just has a few properties and classes in it, so I don't think that's relevant to the problem. Here's the declaration though.

internal class ModelContainer : DbContext
{
    ...
}
1
8
4/18/2014 11:15:36 PM

Popular Answer

Have you tried using the '-Force' parameter in the package manager console?

E.g.

Update-Database -Force -Verbose
6
4/18/2014 11:37:52 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow