现有 EF 迁移在重构后变得不可见

Existing EF migrations became invisible after refactoring

我在我的项目中使用 EF 代码优先迁移。目前我有 2 次迁移。 试图从头开始创建数据库,但 update-database returns 出现错误

No migrations configuration type was found in the assembly 'Project.DAL'

另一方面enable-migrationsreturns

Migrations have already been enabled in project 'Project.DAL'

当我启动 Project 时,我有以下配置:Project.ApiProject.WebProject.Shared(迁移在此处)。然后我将 Project.Shared 分离到 Project.BLLProject.ModelProject.DAL(现在这里是迁移)。也许变化是目前情况的原因。

经过几天的调查,我自己发现了错误。 在重构期间,我将 Configuration 的无参数构造函数从

更改为
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        ContextKey = "Project.DAL.ApplicationDbContext";
    }

    public Configuration(bool automaticMigrationsEnabled = false)
    {
        AutomaticMigrationsEnabled = automaticMigrationsEnabled;
        ContextKey = "Project.DAL.ApplicationDbContext";
    }

我认为转换是等价的,但似乎不是。我将旧的构造函数放在新的构造函数附近,一切正常。