迁移脚本如下所示:
migrationBuilder.CreateTable(
name: "ContractCustomer",
columns: table => new
{
ContractId = table.Column<int>(nullable: false),
CustomerId = table.Column<int>(nullable: false),
Id = table.Column<int>(nullable: false).Annotation("SqlServer:Identity", "1, 1"),
CreationTime = table.Column<DateTime>(nullable: false),
},
constraints: table =>
{
table.UniqueConstraint("UX", x => new {x.ContractId, x.VerzorgerId});
table.PrimaryKey("PK_ContractVerzorger", x => x.Id);
});
Id
它是自动递增的。
Contract
ContractCustomer
然后我得到以下错误:
当identity\u insert设置为OFF时,无法为表“ContractCustomer”中的identity列插入显式值。
使用SQL Server Profiler时,我看到它正在尝试运行以下查询:
INSERT INTO [ContractCustomer] ([Id], [ContractId], [CustomerId], [CreationTime])
VALUES (0, 2, 1, '2020-09-12 13:33:54.2629678');
身份证件
到
0
. 但它保存变化的部分是在幕后发生的。
0
让它自己产生
身份证件
号码?或者在我的迁移脚本中有什么可以调整的吗?