EF Migrations - Allow Data Loss on a single migration

ef-migrations entity-framework entity-framework-6

Question

In the Configuration of Entity Framework migrations, you can add this line:

AutomaticMigrationDataLossAllowed = true;

which will allow data loss when (e.g.) dropping columns.

Is there a way to do this only on specific migrations?

i.e. I wouldn't want to have this permanently set, but if I scaffold a migration that has data loss, I'd like to have to manually go into that migration and do something like this:

public partial class removing_date_time : DbMigration
{
    public override void Up()
    {
        Configuration.AutomaticMigrationDataLossAllowed = true;
        //...

Is that possible?

1
3
11/22/2016 1:41:25 PM

Accepted Answer

You cannot do that.

B'cos that property is for the automatic migration.You cannot use it with Code Based Migration (i.e with Up() and Down()).That property belongs to the DbMigrationsConfiguration class.

You can read more about it here : AutomaticMigrationDataLossAllowed Property

0
11/22/2016 2:29:48 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