如何通过首先通过Migration DB更新列数据类型和长度

时间:2018-08-01 06:29:20

标签: asp.net-mvc database database-migration ef-migrations

我想更新数据库中的模型更改。其实在我通过迁移通过以下代码更新数据库之前

        public int id { get; set; }
        [Required]            
        public string Name { get; set; }
        [Required]
        public string Icon { get; set; }
        [Required]
        [StringLength(maximumLength: 150, MinimumLength = 50)]
        public string Description { get; set; }
        public string Date { get; set; }

但是现在我想更新以下代码

        public int id { get; set; }
        [Required]
        [StringLength(maximumLength: 50)]
        public string Name { get; set; }
        [Required]
        [StringLength(maximumLength:50)]
        public string Icon { get; set; }
        [Required]
        [StringLength(maximumLength: 150, MinimumLength = 50)]
        public string Description { get; set; }
        //[Column(TypeName = "Date")]
        public DateTime? Date { get; set; }

但收到此错误

Cannot insert the value NULL into column 'Date', table 'ConstructionDb.dbo.Services'; column does not allow nulls. UPDATE fails.
The statement has been terminated.

0 个答案:

没有答案