【发布时间】:2017-11-22 04:18:33
【问题描述】:
我已经有一个从零开始创建的数据库(在 __MigrationHistory 表中具有迁移历史记录)和项目。我使用了“数据库中的代码优先”选项并生成了所有类。现在我想再创建一个表,我创建了一个类:
[Table("Companies")]
public partial class Company
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
然后我为我的上下文启用了迁移(项目中有 2 个上下文,使用了 2 个 DB):
Enable-Migrations -ProjectName Infrastructure -ContextTypeName Infrastructure.Asset.AssetContext
它创建了“迁移”文件夹和 Configuration.cs 文件。
接下来,我尝试添加迁移:
Add-Migration -Name Company -ProjectName Infrastructure
它创建迁移,但对已经存在的表使用 Create (Drop)。
为什么?我只想创造差异。
【问题讨论】:
标签: c# entity-framework ef-code-first entity-framework-migrations