Monojit Sarkar
Monojit Sarkar

Reputation: 2451

Entity Framework: How to upgrade or downgrade during migration

this is my migration code AddIsDefault. now tell me how could i down grade later after upgrade and again upgrade later. what command i need to issue at package manager console.

public partial class AddIsDefault : DbMigration
    {
        public override void Up()
        {
            AddColumn("dbo.Contacts", "IsDefault", c => c.Boolean(nullable: false));
        }

        public override void Down()
        {
            DropColumn("dbo.Contacts", "IsDefault");
        }
    }

Upvotes: 1

Views: 466

Answers (1)

Sampath
Sampath

Reputation: 65938

You don't need to downgrade here.If you don't need IsDefault column then remove it on the model and run migration again as shown below.

PM> Add-Migration "Remove_IsDefault"

PM> Update-Database

Later if you need to add it again,change the model and run it again for the new change.Very simple :)

Update :

On Package Manager Console :

PM> Update-Database –TargetMigration: YourMigrationScriptName 

Reference : Code First Migrations

Upvotes: 1

Related Questions