AutomaticMigrationDataLossAllowed not working

c# entity-framework

Question

I have an instance where theAutomaticMigrationDataLossAllowed property I ownConfiguration class in Entity Framework 6 is broken.

I have both of the necessary properties set to true, but I still get an update exception warning that possible data loss might happen. Ironically, it suggests that I leave the properties at true even if I already have them there.

How I instantiate my model container is shown below (context).

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

Here is the pertinent section of myModelInitializer class.

internal class ModelInitializer : IDatabaseInitializer<ModelContainer>
{

    private static bool _usedBefore;

    public void InitializeDatabase(ModelContainer context)
    {

        ...

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

Lastly, here is myConfiguration class.

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

    protected override void Seed(ModelContainer context)
    {

    }
}

My ModelContainer I don't believe that's relevant to the issue because class (the context) only contains a few properties and classes. But first, the declaration.

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

Popular Answer

Have you attempted using the package manager console's '-Force' parameter?

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