简体   繁体   中英

How to say Datetime - timestamp without time zone in EF Core 6.0

I migrate an ASP.NET Core project from 3.1 to 6.0.

I have copied old migration and pasted it to our new version

Migration on EF Core 3.1 (old)

migrationBuilder.AddColumn<DateTime>(
                name: "CalendarStartDate",
                table: "DealOverview",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

Migration in EF Core 6.0 (new)

migrationBuilder.AlterColumn<DateTime>(
                name: "StartDate",
                table: "DealOverview",
                type: "timestamp without time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone");

The migration fails because this line

public DateTime StartDate { get; set; }

has changed.

I want from this package:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />

to this package:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" /> 

EF Core 6 Npgsql has introduced some breaking changes to timestamp handling logic. You can try to "revert" back to old behaviour by adding next line either to Startup or Program file:

AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM