I am using EF code first for my project. I have following code in my DataModel
[HiddenInput(DisplayValue = false)]
public DateTime? PasswordDate { get; s
That's because you allowed NULL
values in that column, then tried to make it non-nullable. It will subsequently try to migrate your existing data into that newly non-nullable column, which will break because you already have NULL
values in there.
Two solutions:
1) Change it back to nullable
2) Give it a default value for items that don't have a value.
It's not possible to directly add a non-nullable column to a table that has historical data in the table if no default value is provided for that column.
What I do is
Code example(with postgres database):
public override void Up()
{
AddColumn("public.YourTableName", "YourColumnName", c => c.Int(nullable: true));
Sql(@"UPDATE ""public"".""YourTableName""
SET ""YourColumnName"" = Value you want to set
");
AlterColumn("public.YourTableName", "YourColumnName", c => c.Int(nullable: false));
}