{"record":{"id":"c4358d523af4c174","repo":"dotnet/efcore","slug":"the-down-method-for-this-migration-has-not-been","errorCode":null,"errorMessage":"The 'Down' method for this migration has not been implemented. Both the 'Up' and 'Down' methods must be implemented to support reverting migrations.","messagePattern":"The 'Down' method for this migration has not been implemented\\. Both the 'Up' and 'Down' methods must be implemented to support reverting migrations\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/Migration.cs","lineNumber":142,"sourceCode":"    ///     Builds the operations that will migrate the database 'down'.\n    /// </summary>\n    /// <remarks>\n    ///     <para>\n    ///         That is, builds the operations that will take the database from the state left in by\n    ///         this migration so that it returns to the state that it was in before this migration was applied.\n    ///     </para>\n    ///     <para>\n    ///         This method must be overridden in each class that inherits from <see cref=\"Migration\" /> if\n    ///         both 'up' and 'down' migrations are to be supported. If it is not overridden, then calling it\n    ///         will throw and it will not be possible to migrate in the 'down' direction.\n    ///     </para>\n    ///     <para>\n    ///         See <see href=\"https://aka.ms/efcore-docs-migrations\">Database migrations</see> for more information and examples.\n    ///     </para>\n    /// </remarks>\n    /// <param name=\"migrationBuilder\">The <see cref=\"MigrationBuilder\" /> that will build the operations.</param>\n    protected virtual void Down(MigrationBuilder migrationBuilder)\n        => throw new NotSupportedException(RelationalStrings.MigrationDownMissing);\n\n    private List<MigrationOperation> BuildOperations(Action<MigrationBuilder> buildAction)\n    {\n        var migrationBuilder = new MigrationBuilder(ActiveProvider);\n        buildAction(migrationBuilder);\n\n        return migrationBuilder.Operations;\n    }\n}\n","sourceCodeStart":124,"sourceCodeEnd":152,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/Migration.cs#L124-L152","documentation":"Migration.Down(MigrationBuilder) has its default implementation throw NotSupportedException. The base class deliberately does this so that 'down' migrations fail loudly unless each migration explicitly overrides Down with the inverse operations. Triggered whenever EF tries to revert past this migration (e.g. 'dotnet ef database update <PreviousMigration>' or Migrator with a target before this one).","triggerScenarios":"Calling Database.Migrate(previousMigration), 'dotnet ef migrations remove' on a migration without Down, 'dotnet ef database update' to an earlier migration, or programmatic revert where the migration class never overrode Down.","commonSituations":"Scaffolder/emitted migration where only Up was written; hand-written migration left half-finished; third-party migration without a Down; using a migration generated by an older tooling version.","solutions":["Override protected override void Down(MigrationBuilder migrationBuilder) in the migration and emit the inverse of each Up operation (DropColumn, DropTable, etc.).","If the migration is the latest and you never revert, you can ignore it — but add Down anyway for safety.","Use 'dotnet ef migrations remove' instead of 'update <previous>' to undo the most recent migration when Down is missing."],"exampleFix":"// before\npublic partial class AddAudit : Migration\n{\n    protected override void Up(MigrationBuilder migrationBuilder)\n        => migrationBuilder.AddColumn<string>(\"User\", \"Orders\");\n    // Down omitted -> throws\n}\n\n// after\npublic partial class AddAudit : Migration\n{\n    protected override void Up(MigrationBuilder migrationBuilder)\n        => migrationBuilder.AddColumn<string>(\"User\", \"Orders\");\n\n    protected override void Down(MigrationBuilder migrationBuilder)\n        => migrationBuilder.DropColumn(\"User\", \"Orders\");\n}","handlingStrategy":"validation","validationCode":"// Scan migrations for a missing Down override before applying\nforeach (var m in db.GetService<IMigrationsAssembly>().Migrations.Values)\n{\n    var down = m.GetType().GetMethod(\n        \"Down\",\n        BindingFlags.Instance | BindingFlags.NonPublic,\n        null, new[] { typeof(MigrationBuilder) }, null);\n    if (down?.DeclaringType == typeof(Migration))\n        throw new InvalidOperationException(\n            $\"Migration {m.GetType().Name} has no Down override.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always scaffold both Up and Down when writing a migration.","Add a test that reflects over every migration class and asserts Down is overridden.","Use 'dotnet ef migrations remove' to undo the latest migration instead of reverting when Down is missing."],"tags":["migrations","reverting","not-implemented"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}