我正在使用实体框架。该表已存在,列为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.
有没有办法让它不尝试创建列并认识到现有的列应该使用它?
答案 0 :(得分:0)
您可以在更新数据库之前编辑迁移。删除重复项,看看会发生什么。
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",
…
);
});