Search code examples
datetimeentity-framework-6database-migrationdatetime2

Conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value during migration EF 6


When applying a migration using "update-database" I get an error about conversion of datetime2 to datetime. How do I fix this?


Solution

  • Oh... I found the answer. You have to add the following line to the OnModelCreating method in your DbContext class:

    modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2"));