我將 ASP.NET Core 專案從 3.1 遷移到 6.0。
我已復制舊遷移并將其粘貼到我們的新版本
EF Core 3.1(舊)上的遷移
migrationBuilder.AddColumn<DateTime>(
name: "CalendarStartDate",
table: "DealOverview",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
EF Core 6.0 中的遷移(新)
migrationBuilder.AlterColumn<DateTime>(
name: "StartDate",
table: "DealOverview",
type: "timestamp without time zone",
nullable: false,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
遷移失敗,因為這條線
public DateTime StartDate { get; set; }
已經改變。
我想從這個包中:
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
到這個包:
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" />
uj5u.com熱心網友回復:
EF Core 6 Npgsql對時間戳處理邏輯進行了一些重大更改。您可以嘗試通過將下一行添加到Startup或Program檔案來“恢復”到舊行為:
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
但總的來說,建議遷移到新的行為。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/408057.html
標籤:
