Frequently asked questions

Decisions to make before adopting the library or moving an existing migration project.

Examples use Classic and Fluent tabs. Your choice follows you through the manual.

Do I need an ORM?

No. Migrations operate on an ADO.NET connection through the transformation provider. Use EF, Dapper, another data layer or direct SQL in the rest of your application. Migrator does not scaffold schema changes from an object model.

Can I mix Classic and Fluent?

Yes. Both implement the same migration contract, run through the same loader and share history. Keep each version unique. The tabs throughout these guides show equivalent choices, not two classes to install together. The authoring method names differ: Up/Down versus BuildUp/BuildDown.

CreateUsers.cs

Classic

using System.Data;
using DotNetProjects.Migrator.Framework;

[Migration(1)]
public class CreateUsers : Migration
{
    public override void Up()
    {
        Database.AddTable("Users",
            new Column("Id", DbType.Int32) { IsNullable = false },
            new Column("Name", DbType.String, 255),
            new PrimaryKeyConstraint("PK_Users", "Id"));
    }

    public override void Down() => Database.RemoveTable("Users");
}

Fluent

using DotNetProjects.Migrator.Framework;
using DotNetProjects.Migrator.Framework.Fluent;

[Migration(1)]
public class CreateUsers : FluentMigration
{
    public override void BuildUp(MigrationBuilder migration)
    {
        migration.Create.Table("Users")
            .WithColumn("Id").AsInt32().NotNullable()
            .WithColumn("Name").AsString(255)
            .WithPrimaryKey("PK_Users", "Id");
    }

    public override void BuildDown(MigrationBuilder migration)
        => migration.Delete.Table("Users");
}

Choose one authoring style

Why does SQLite rebuilding matter?

SQLite does not implement every ALTER TABLE operation. Migrator reads the live schema and reconstructs a supported table when a column or constraint change needs it. This is useful without an ORM model. See SQLite for preserved objects, foreign-key checks and reconstruction boundaries.

Does rollback recover data?

A transaction can roll back a failed migration when its database operations are transactional. Downgrading a completed version executes your reverse method. Neither mechanism recovers rows already deleted by a successful migration. Use an explicit recovery design and backups for that case.

Can I edit an applied migration?

The journal records versions, scopes and timestamps, not a content checksum. Editing an applied class will not make it rerun. Add a new migration for a change. Consolidated baselines are an explicit history operation; read versioning and history.

Why does SQL preview reject my migration?

Preview renders a structured subset. A provider callback, unsupported constraint alteration or schema dependency after raw SQL cannot be represented reliably and raises an error. Read planning and SQL preview rather than treating preview as a full execution simulation.