EF The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

StackOverflow https://stackoverflow.com/questions/23675980

  •  23-07-2023
  •  | 
  •  

문제

I Have read more similar questions as this...

I have created a BD but after to creation I thought to add a DateTime field to save the datetime registration, but when I type update-database (after creation the migration), the Package Manager Console show me the error of the title

I already tried this:

AlterColumn("dbo.Dispositivoes", "RegisterDate", c => c.DateTime(nullable: false, defaultValueSql: "GETDATE()"));
AlterColumn("dbo.Dispositivoes", "RegisterDate", c => c.DateTime(nullable: false, defaultValue: DateTime.Now));

new DataColumn("myDate", typeof(DateTime));

This show ever the same error. I do not have idea to resolve this, any help me please?

Thanks!!

도움이 되었습니까?

해결책

have you tried

Sql("alter table dbo.Dispositivoes alter column RegisterDate datetime2 not null default getdate()")

or

AlterColumn("dbo.Dispositivoes", "RegisterDate", c => c.DateTime(nullable: false, storeType: "datetime2", defaultValueSql: "GETDATE()"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top