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