【发布时间】:2020-05-27 01:47:05
【问题描述】:
我有一个现有的填充表。使用 EF Core 迁移,我想创建一个 DB 生成的主键。
这是我的流畅 API:
modelBuilder.Entity<MyTable>()
.HasKey(a => a.Id);
modelBuilder.Entity<MyTable>()
.Property(p => p.Id)
.ValueGeneratedOnAdd();
我遇到的问题是,当我运行迁移时,我收到一个错误,因为表中的现有行没有填充这个(新)字段:
The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.MyTable' and the index name 'PK_MyTable'. The duplicate key value is ().
有没有一种方法可以利用默认值来使用主键追溯填充此表?或者,是否有另一种方法可以追溯填充此字段?
【问题讨论】:
标签: entity-framework .net-core entity-framework-core