Why are the default DateTime values dropped when migrating using EF Core 6?

46 Views Asked by At

I am currently using EF Core 6.0.15 and had been using EF 5 previously on the same code base meaning that I was able to perform migrations without seeing the current problem.

I have the following models (only showing one DateTime property to keep focus):

public class DistributionStatus
{
  public DateTime ApproxDownloadedDateTime{ get; set; }
}

public class IsdIndex
{
  public DateTime IoTCloudDeprecationDateTime{ get; set; }
}

and I don't have Data Annotations on either property.

Here is the dB before migration:

State before migration

which shows that there is a default value of -infinity for both DateTime properties.

Now, even though there are no changes in any of my Models, when I create the migration, I get:

            migrationBuilder.AlterColumn<DateTime>(
                name: "ApproxDownloadedDateTime",
                table: "DistributionStatuses",
                type: "timestamp with time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldDefaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));

This for me raises 2 questions, which I hope I can get clarity on:

  1. Why is this code created to drop the default DateTime value for table DistributionStatuses?
  2. Why is the same code not happening for table IsdIndex?

Moreover, in my model context, I am not setting default values for these tables.

0

There are 0 best solutions below