abpframework/abp · error · Exception

DbMigrator is not found!

Error message

DbMigrator is not found!

What it means

Thrown by CreateMigrationAndRunMigratorCommand when the --nolayers flag is NOT set and GetDbMigratorProjectPath returns null — meaning no project folder ending in '.DbMigrator' was found as a sibling of the DbMigrations folder. The command searches the parent directory of the given DbMigrations path for any subdirectory matching the *.DbMigrator pattern, then looks for a .csproj inside it. If neither exists, it cannot run the migrator and throws a plain Exception.

Source

Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs:46

        CmdHelper = cmdHelper;
        DotnetEfToolManager = dotnetEfToolManager;
        Logger = NullLogger<CreateMigrationAndRunMigratorCommand>.Instance;
    }

    public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs)
    {
        if (commandLineArgs.Target.IsNullOrEmpty())
        {
            throw new CliUsageException("DbMigrations folder path is missing!");
        }

        var dbMigrationsFolder = commandLineArgs.Target;

        var nolayers = commandLineArgs.Options.ContainsKey("nolayers");
        var dbMigratorProjectPath = GetDbMigratorProjectPath(dbMigrationsFolder);
        if (!nolayers && dbMigratorProjectPath == null)
        {
            throw new Exception("DbMigrator is not found!");
        }

        await DotnetEfToolManager.BeSureInstalledAsync();

        var migrationsCreatedSuccessfully = await _initialMigrationCreator.CreateAsync(commandLineArgs.Target, !nolayers);

        if (migrationsCreatedSuccessfully)
        {
            if (nolayers)
            {
                CmdHelper.RunCmd("dotnet run --migrate-database", Path.GetDirectoryName(Path.Combine(dbMigrationsFolder, "MyCompanyName.MyProjectName")));
            }
            else
            {
                CmdHelper.RunCmd("dotnet run",  Path.GetDirectoryName(dbMigratorProjectPath));
            }
            await Task.CompletedTask;
        }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Verify a project folder named '<SolutionName>.DbMigrator' exists as a sibling of the DbMigrations folder you specified
  2. Ensure that folder contains a .csproj file (GetFiles looks for files ending in '.csproj')
  3. If you are working with a single-layer (nolayers) solution, add the --nolayers flag to skip the DbMigrator lookup
  4. Adjust the DbMigrations folder path argument so its parent directory contains the .DbMigrator project

Example fix

// before — wrong parent folder
abp create-migration-and-run-migrator ./wrong/path/DbMigrations

// after — path whose sibling contains MyProject.DbMigrator
abp create-migration-and-run-migrator ./src/MyProject.DbMigrations
Defensive patterns

Strategy: validation

Validate before calling

// Verify the .DbMigrator project exists as a sibling of the DbMigrations folder
var parentDir = Directory.GetParent(dbMigrationsPath);
var dbMigratorDir = parentDir?.GetDirectories().FirstOrDefault(d => d.Name.EndsWith(".DbMigrator"));
if (dbMigratorDir == null || !dbMigratorDir.GetFiles("*.csproj").Any())
{
    Console.Error.WriteLine("Error: No .DbMigrator project found next to the DbMigrations folder.");
    return;
}

Try / catch

try
{
    await command.ExecuteAsync(args);
}
catch (Exception ex) when (ex.Message == "DbMigrator is not found!")
{
    logger.LogError("Ensure the solution has a *.DbMigrator project or use --nolayers.");
}

Prevention

When it happens

Trigger: Running the migration+migrator command in a layered solution where the DbMigrator project is absent, misnamed (does not end in '.DbMigrator'), located in a different directory structure, or has no .csproj file inside its folder. The check `!nolayers && dbMigratorProjectPath == null` fires.

Common situations: The solution structure was altered or the DbMigrator project was renamed/deleted. Developer points to the wrong DbMigrations folder whose parent directory does not contain the DbMigrator sibling. Template modifications that moved projects around without updating directory conventions.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/d4c7f8a0b2595c68. Report an issue: GitHub.