/

3 March 2025

Database Migrations in .NET Core: EF Core, DbUp, FluentMigrator and Liquibase

Comparing EF Core, DbUp, FluentMigrator and Liquibase

Managing database schema changes efficiently is essential for maintaining application stability and ensuring smooth deployments. .NET Core provides multiple tools for handling migrations, each with its own advantages and drawbacks.

In this article, we’ll compare Entity Framework (EF) Core Migrations, DbUp, FluentMigrator, and Liquibase, evaluating them based on:

πŸ”Ή Simplicity – Ease of setup and usage.
πŸ”Ή Ease of Use – Developer experience when creating and applying migrations.
πŸ”Ή Speed of Development – How quickly schema changes can be applied.
πŸ”Ή Known Problems – Common challenges and limitations of each tool.

1. Entity Framework Core Migrations

πŸ’‘ Best for: Applications using EF Core ORM that need automatic database migrations.

EF Core Migrations enables developers to manage schema changes through C# migration scripts rather than raw SQL.

How It Works

πŸ”Ή Define models in C#.
πŸ”Ή EF Core compares model changes and generates migrations.
πŸ”Ή Run dotnet ef migrations add <name> to create a migration.
πŸ”Ή Apply changes using dotnet ef database update.

Setup

  1. 1. Install EF Core CLI tools: dotnet tool install --global dotnet-ef
  2. 2. Add the EF Core NuGet package: dotnet add package Microsoft.EntityFrameworkCore.SqlServer
  3. 3. Create a migration: dotnet ef migrations add InitialCreate
  4. 4. Apply migrations: dotnet ef database update

Pros & Cons

βœ… Pros❌ Cons
Fully integrated with EF CoreHarder to manage complex migrations
Auto-generates SQL for schema changesNot ideal for raw SQL-based modifications
Easy rollback supportCan be slow for large databases
Works with multiple database providersLimited control over migration scripts

Known Problems

πŸ”Ή Generated SQL may not be optimal – The automatic SQL script can sometimes be inefficient, requiring manual optimization.
πŸ”Ή Migrations can get out of sync – If different team members modify models but forget to add migrations, EF Core can generate conflicting scripts.
πŸ”Ή Renaming tables/columns can cause data loss – EF treats renames as drop-and-create operations unless explicitly handled with RenameColumn or RenameTable.

Verdict

πŸ”Ή Simplicity: β­β­β­β­β˜† (Easy for EF Core users)
πŸ”Ή Ease of Use: β­β­β­β­β˜† (Good for ORM-based applications)
πŸ”Ή Speed of Development: β­β­β­β­β˜† (Quick for model-first workflows)

2. DbUp

πŸ’‘ Best for: Developers who prefer raw SQL migrations with version tracking.

DbUp is a lightweight migration tool that runs SQL scripts in sequence and tracks which ones have already been applied.

How It Works

πŸ”Ή Write SQL scripts (.sql files).
πŸ”Ή DbUp logs applied scripts in a database table.
πŸ”Ή Runs new scripts on application startup or manually via a runner.

Setup

  1. 1. Install the NuGet package: dotnet add package DbUp
  2. 2. Create a migration runner:
var upgrader = DeployChanges.To
    .SqlDatabase("YourConnectionString")
    .WithScriptsFromFileSystem("Migrations")
    .LogToConsole()
    .Build();

var result = upgrader.PerformUpgrade();

Pros & Cons

βœ… Pros❌ Cons
Simple and flexibleNo built-in rollback support
Full control over SQLNo automatic schema generation
No ORM dependencyNo explicit migration structure
Good for database-first projectsRequires manual tracking

Known Problems

πŸ”Ή No rollback mechanism – If a migration fails, rolling back requires manually writing a reverse SQL script.
πŸ”Ή Manual script tracking – Developers must ensure scripts are numbered properly to avoid duplicate executions.
πŸ”Ή Schema drift risk – Since it’s SQL-based, developers might make changes outside of migrations, leading to inconsistencies.

Verdict

πŸ”Ή Simplicity: ⭐⭐⭐⭐⭐ (Very simple, pure SQL)
πŸ”Ή Ease of Use: β­β­β­β­β˜† (No ORM overhead, but manual tracking)
πŸ”Ή Speed of Development: β­β­β­β˜†β˜† (Slower than EF Core for model-first workflows)

3. FluentMigrator

πŸ’‘ Best for: Developers who want code-based migrations without using EF Core ORM.

FluentMigrator enables structured C#-based migrations using a fluent API, providing more control than EF Core while avoiding raw SQL.

How It Works

πŸ”Ή Define migrations in C# classes instead of SQL.
πŸ”Ή Use a fluent API to describe schema changes.
πŸ”Ή Run migrations via CLI or integrate into application startup.

Setup

  1. 1. Install FluentMigrator: dotnet add package FluentMigrator.Runner
  2. 2. Define a migration
  3. 3. Run migrations: dotnet ef migrations update
[Migration(20250301)]
public class AddUsersTable : Migration
{
    public override void Up()
    {
        Create.Table("Users")
            .WithColumn("Id").AsInt32().PrimaryKey().Identity()
            .WithColumn("Name").AsString(255).NotNullable();
    }

    public override void Down()
    {
        Delete.Table("Users");
    }
}

Pros & Cons

βœ… Pros❌ Cons
Code-based migrations (no SQL required)Learning curve for fluent API
Database-agnosticRequires manual execution setup
Supports rollbackSlower than raw SQL execution
Good for large teamsRequires writing migration tracking manually

Known Problems

πŸ”Ή Steep learning curve – The fluent API syntax can be hard to grasp for developers used to SQL.
πŸ”Ή Migration history maintenance – Developers must ensure proper ordering and dependency handling.
πŸ”Ή Limited built-in tooling – Unlike EF Core, FluentMigrator doesn’t provide integrated database management commands.

Verdict

πŸ”Ή Simplicity: β­β­β­β˜†β˜† (More complex than EF Core)
πŸ”Ή Ease of Use: β­β­β­β­β˜† (Structured, but not automatic)
πŸ”Ή Speed of Development: β­β­β­β˜†β˜† (Slower than EF Core for small projects)

4. Liquibase

πŸ’‘ Best for: Teams managing large-scale databases with version-controlled SQL scripts.

Liquibase is a cross-platform migration tool that allows defining schema changes in SQL, XML, YAML, or JSON formats.

How It Works

πŸ”Ή Define schema changes in ChangeLog files.
πŸ”Ή Track applied migrations in a database changelog table.
πŸ”Ή Execute migrations via CLI or integrate into CI/CD pipelines.

Setup

  1. 1. Install Liquibase CLI: brew install liquibase
  2. 2. Create a changelog.xml
  3. 3. Apply migrations: liquibase update
<databaseChangeLog>
    <changeSet id="1" author="dev">
        <createTable tableName="Users">
            <column name="Id" type="int" autoIncrement="true">
                <constraints primaryKey="true"/>
            </column>
            <column name="Name" type="varchar(255)"/>
        </createTable>
    </changeSet>
</databaseChangeLog>

Pros & Cons

βœ… Pros❌ Cons
Supports multiple formats (SQL, XML, JSON)Requires Liquibase setup
Good for large teams and CI/CDMore complex than EF Core or DbUp
Works well with version controlSlower development cycle
Rollback & auditing supportNot .NET-native

Known Problems

πŸ”Ή Requires extra setup – Unlike EF Core or DbUp, Liquibase is not built into .NET Core and requires separate configuration.
πŸ”Ή Complex for small projects – Managing multiple formats (SQL, XML, JSON) can be overkill for simple applications.
πŸ”Ή Potential merge conflicts – Since it tracks migrations in separate files, teams working simultaneously might create conflicting changesets.

Verdict

πŸ”Ή Simplicity: β­β­β˜†β˜†β˜† (More setup required)
πŸ”Ή Ease of Use: β­β­β­β˜†β˜† (Powerful, but steeper learning curve)
πŸ”Ή Speed of Development: β­β­β­β˜†β˜† (Better for enterprise, slower for small projects)

Final Comparison Table

ToolSimplicityEase of UseSpeed of DevelopmentKnown Issues
EF Coreβ­β­β­β­β˜†β­β­β­β­β˜†β­β­β­β­β˜†Model-sync issues, inefficient SQL, renaming pitfalls
DbUpβ­β­β­β­β­β­β­β­β­β˜†β­β­β­β˜†β˜†No rollback, manual script tracking, schema drift
FluentMigratorβ­β­β­β˜†β˜†β­β­β­β­β˜†β­β­β­β˜†β˜†Learning curve, ordering issues, limited tooling
Liquibaseβ­β­β˜†β˜†β˜†β­β­β­β˜†β˜†β­β­β­β˜†β˜†Setup complexity, merge conflicts, CI/CD integration overhead

Conclusion

πŸ”Ή DbUp β†’ Ideal for SQL-first projects where developers want full control over scripts.
πŸ”Ή FluentMigrator β†’ Great for teams wanting structured, C#-based migrations without an ORM.
πŸ”Ή EF Core β†’ Best for ORM-driven applications that need automatic migrations.
πŸ”Ή Liquibase β†’ Best suited for enterprise projects with complex migration needs across teams.

πŸš€ Choosing the right tool depends on your project’s workflow and database complexity!


If you don’t know what to choose, feel free to contact us!

    Β© 2024 TechPals. All Rights Reserved.

  • Plastira 2, 73100, Chania, Greece
  • Reg. number: 162486758000
  • VAT ID: 801740930
  • TECHPALS P.C. COMPUTER SOFTWARE SERVICES