{"record":{"id":"eef553f23c2b6aeb","repo":"abpframework/abp","slug":"migrations-failed-a-migration-command-didn-t-run","errorCode":null,"errorMessage":"Migrations failed! A migration command didn't run successfully.","messagePattern":"Migrations failed! A migration command didn't run successfully\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs","lineNumber":70,"sourceCode":"\n        if (migrationsCreatedSuccessfully)\n        {\n            if (nolayers)\n            {\n                CmdHelper.RunCmd(\"dotnet run --migrate-database\", Path.GetDirectoryName(Path.Combine(dbMigrationsFolder, \"MyCompanyName.MyProjectName\")));\n            }\n            else\n            {\n                CmdHelper.RunCmd(\"dotnet run\",  Path.GetDirectoryName(dbMigratorProjectPath));\n            }\n            await Task.CompletedTask;\n        }\n        else\n        {\n            var exceptionMsg = \"Migrations failed! A migration command didn't run successfully.\";\n\n            Logger.LogError(exceptionMsg);\n            throw new Exception(exceptionMsg);\n        }\n    }\n    \n    private static string GetDbMigratorProjectPath(string dbMigrationsFolderPath)\n    {\n        var srcFolder = Directory.GetParent(dbMigrationsFolderPath);\n        var dbMigratorDirectory = Directory.GetDirectories(srcFolder.FullName)\n            .FirstOrDefault(d => d.EndsWith(\".DbMigrator\"));\n\n        return dbMigratorDirectory == null\n            ? null\n            : Directory.GetFiles(dbMigratorDirectory).FirstOrDefault(f => f.EndsWith(\".csproj\"));\n    }\n\n    public string GetUsageInfo()\n    {\n        return string.Empty;\n    }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs#L52-L88","documentation":"Thrown by CreateMigrationAndRunMigratorCommand when _initialMigrationCreator.CreateAsync returns false, indicating that the EF Core migration command ('dotnet ef migrations add ...') failed to execute successfully. This is a downstream failure: the migration creation step itself errored, so this exception propagates the failure to the caller. The error is logged via Logger.LogError before throwing.","triggerScenarios":"InitialMigrationCreator.CreateAsync returns false because the underlying 'dotnet ef migrations add InitialCreate' command failed — causes include missing EF Core tools, invalid DbContext configuration, database connection issues during model snapshot generation, or compilation errors in the migration project.","commonSituations":"EF Core design-time tools not installed or wrong version, DbContext has configuration errors (missing connection string, invalid provider), the project doesn't compile, or there's a mismatch between EF Core runtime and tools packages. CI environments where dotnet-ef global tool is not pre-installed.","solutions":["Install/update EF Core tools: `dotnet tool install --global dotnet-ef` or `dotnet tool update --global dotnet-ef`","Ensure the DbMigrations project builds cleanly: `dotnet build` in the project folder and fix any compilation errors","Check the DbContext and its configuration (connection string, provider package, OnModelCreating) for errors","Verify the EF Core tools version matches the EF Core runtime package version in your .csproj","Run `dotnet ef migrations add InitialCreate` manually in the DbMigrations project to see the detailed error output"],"exampleFix":"N/A","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure EF Core tools are installed and project builds\nvar efCheck = CmdHelper.RunCmdAndGetOutput(\"dotnet ef --version\");\nif (efCheck.ExitCode != 0)\n{\n    Console.Error.WriteLine(\"Install dotnet-ef: dotnet tool install --global dotnet-ef\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await command.ExecuteAsync(args);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"Migrations failed\"))\n{\n    logger.LogError(\"EF Core migration creation failed. Run 'dotnet ef migrations add InitialCreate' manually for details.\");\n    // The underlying EF error is swallowed; surface it by running the migration manually\n}","preventionTips":["Ensure dotnet-ef global tool is installed and matches the EF Core package version","Build the DbMigrations project successfully before running the migration command","Validate DbContext configuration and connection strings beforehand","Run the EF migration command manually first to catch detailed errors"],"tags":["cli","abp-cli","migration","ef-core","build-failure"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}