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?
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