How to delete or change after Migration done?

Topics: Writing modules
Oct 4, 2012 at 11:13 AM

hi there

How to delete or change after Migration done without deleting the module's table?

im create a module with 5 fields inserted to db via migration, now i want to add another Field but dont know how. For now i have to delete the the table of that module and rerun.

Thanks.

Jerry.

 

Developer
Oct 6, 2012 at 5:04 AM

Do you mean: how to delete or alter columns of an existing table that you created as part of your migration? If so, just add an extra migration step to your migrations class and use the AlterTable method of the SchemaBuilder. It works like CreateTable, but you'll be provided with different methods like DropColumn to drop a column, WithName to change the name, and an AlterColumn method to do more stuff.

SchemaBuilder
                .AlterTable("MyTable", table => {
                    table.DropColumn("MyColumn"); // Drop a column
                    table.AddColumn<int>("NewColumn"); // Add a column
                    table.AlterColumn("AnotherColumn", c => c.WithType(DbType.Int64)); // change type of column
                }