How to drop column with FluentMigrator?
Asked Answered
R

1

39

I am using .Net4.5 and C#, I am working on one of database migrations using FluentMigrator. I am able to alter tables and add columns by using

Alter.Table("Items").InSchema("Pricing")
            .AddColumn("CanBe").AsBoolean().NotNullable()

However I need to drop some existing columns and nor DeleteColumn nor DropColumn methods are not on IAlterTableAddColumnOrAlterColumnOrSchemaSyntax interface.

How do I drop columns using FluentMigrator?

Rosemarierosemary answered 7/7, 2016 at 10:59 Comment(0)
R
73

Found it myself:

It has to go as separate statement.

Alter.Table("Items").InSchema("Pricing")
        .AddColumn("CanBe").AsBoolean().NotNullable();

Delete.Column("AllowSubscription").FromTable("Items").InSchema("Pricing");
Rosemarierosemary answered 7/7, 2016 at 11:2 Comment(4)
Shame there isn't an option for .DeleteColumn within Alter.Table :(Dinner
@Dinner Indeed. I think it is due to this being 'translated' into SQL statements.Rosemarierosemary
What do you do if there's a foreign key?Worm
@KellenStuart A few year too late, but you just remove the foreign key before doing the changesDaradarach

© 2022 - 2024 — McMap. All rights reserved.