1

I'm using EF code first and have the following in my migration file.

public override void Up()
{
    AddColumn("dbo.ConsumerFee", "VATCodeId", c => c.Int(nullable: false, defaultValue: 1));
}

However when the column is added to the table it is given a default value of 0 not 1. When I run the migration manually I can see that it generates this sql :

alter table `ConsumerFee` add column `VATCodeId` int not null

Any ideas what may be up with this?

Chris
  • 69
  • 7
  • Not available in EF6. See [here](http://stackoverflow.com/questions/20136504/how-can-set-a-default-value-constraint-with-entity-framework-6-code-first) – Steve Greene Feb 27 '17 at 13:59

1 Answers1

0

This was happening to me too which was a bummer. However I figured out that the defaultValueSql:"1" will work which sets the default sql expression for this column.

AddColumn("dbo.ConsumerFee", "VATCodeId", c => c.Int(nullable: false, defaultValueSql: "1"));