【问题标题】:Why the Add-migration command of Code First is including all the database instead of a specific change that I made to an entity?为什么 Code First 的 Add-migration 命令包含所有数据库,而不是我对实体所做的特定更改?
【发布时间】:2021-09-03 06:26:50
【问题描述】:

我有课

public class Types
{
    public int ID {get; set;}
    public string name {get; set;}

}

首先使用代码,我使用 add-migration 和 update-database 创建了相同结构的表。

但是当我向它添加另一个属性时。

public string SystemName {get; set;}

然后迁移,然后脚本将整个数据库包含在 up() 函数中,即使我删除了所有以前的迁移文件,也使用 CREATE。

为什么?

【问题讨论】:

    标签: c# entity-framework c#-4.0 dbcontext


    【解决方案1】:

    您是否删除了所有旧的迁移文件?你不应该这样做。通过迁移文件实体框架了解它需要创建数据库的哪一部分。

    【讨论】:

    • 不应该永远不会影响它,已经这样做了很多次并且从未影响我的系统。
    • 然后检查数据库中的迁移表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多