实体框架试图创建重复列
本文关键字:创建 框架 实体 | 更新日期: 2023-09-27 18:12:36
我正在使用实体框架。这个表已经存在,列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",
…
);
});