gpt4 book ai didi

c# - Entity Framework 试图创建重复的列

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:43 25 4
gpt4 key购买 nike

我正在使用 Entity Framework 。该表已存在,其列为 my_column。我将属性 my_column 添加到我的类中以访问该列。然后该程序似乎尝试创建该列,但失败了,因为它已经存在。

Column names in each table must be unique. Column name 'my_column' in table 'my_table' is specified more than once.

有没有办法让它不尝试创建列并识别现有列是它应该使用的列?

最佳答案

您可以在更新数据库之前编辑迁移。删除重复项,看看会发生什么。

            migrationBuilder.CreateTable(

name: "InvoiceConsumers",

columns: table => new

{

…,

InvoiceId = table.Column<int>(nullable: false),

InvoiceId1 = table.Column<int>(nullable: true)

},

constraints: table =>

{

table.PrimaryKey("PK_InvoiceConsumers", x => x.Id);

table.ForeignKey(

name: "FK_InvoiceConsumers_Consumers_ConsumerId",

…);

table.ForeignKey(

name: "FK_InvoiceConsumers_Invoices_InvoiceId",



onDelete: ReferentialAction.Cascade);

table.ForeignKey(



column: x => x.InvoiceId1,

principalTable: "Invoices",



);

});

关于c# - Entity Framework 试图创建重复的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24685789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com