Entity Framework Code first making a column non-nullable

后端 未结 2 818
北荒
北荒 2021-02-05 07:17

I am using EF code first for my project. I have following code in my DataModel

[HiddenInput(DisplayValue = false)]        
public DateTime? PasswordDate { get; s         


        
2条回答
  •  礼貌的吻别
    2021-02-05 07:34

    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.

提交回复
热议问题