Snake Case Reached My EF Core Migrations History Table Too

A wooden card catalog drawer full of cards, pulled out from a wall of labeled drawers

I was looking through a database to see what some webhooks had written when I noticed the EF Core migrations history table didn't follow the snake_case naming convention. Nothing had failed, and I was there for the transaction data, but inconsistent naming in a Postgres database really grates on me. This one had been that way for months.

If you use UseSnakeCaseNamingConvention() from EFCore.NamingConventions, you may have the same thing in your database. How you handle it depends on what your database looks like today.

What happens to the EF Core migrations history table

The setup is the usual one line:


options.UseNpgsql(connectionString)
    .UseSnakeCaseNamingConvention();

Your tables and columns become snake_case, which is what you asked for. However, EF Core also keeps its own table to track applied migrations. With plain Npgsql, EF creates it like this:


CREATE TABLE "__EFMigrationsHistory" (
    "MigrationId" character varying(150) NOT NULL,
    "ProductVersion" character varying(32) NOT NULL,
    CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);

Add the naming convention, and a new database gets this instead:


CREATE TABLE "__EFMigrationsHistory" (
    migration_id character varying(150) NOT NULL,
    product_version character varying(32) NOT NULL,
    CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
);

The columns and primary key name change, but the table name doesn't. You end up with a PascalCase table name wrapped around snake_case columns.

After I noticed the mismatch, an AI agent wrote the fix. I also had an agent build and run a throwaway repro to check the behavior and the options below. The output here comes from Postgres 17, with EFCore.NamingConventions 10.0.1 and Npgsql.EntityFrameworkCore.PostgreSQL 10.0.0. Other versions may behave differently, so check yours.

Issue #1 on the EFCore.NamingConventions repository reported this column renaming back in 2019. When I checked on November 25, 2026, the issue was still open, and the project's README didn't mention the history table.

Why an existing EF Core migrations history table can stop migrating

A brand-new database is consistent with your configuration, even if the names look odd. An existing database is a different story.

Suppose you created the database before you added the convention. Its columns are still MigrationId and ProductVersion, while EF now looks for the new names. In the repro, asking EF for the applied migrations failed:

42703: column "migration_id" does not exist

Your first instinct might be to write a migration that renames the columns. The catch is that EF reads the history table to work out which migrations to apply. With the new configuration active, that read fails before your rename can run.

You can work around the ordering with a configuration change or a manual rename. Either way, the history table and your configuration have to agree first.

Three ways to handle it

Check the actual column names in your EF Core migrations history table before you change anything. Do that for each environment, because a database created before the change can differ from one created after it.

1. Keep EF's default history columns

This option suits an EF Core migrations history table that still has MigrationId and ProductVersion. The SyntaxCircus.EntityFrameworkCore.Postgres package wraps the convention for this case. It's one of our open-source .NET libraries:


options.UseNpgsql(connectionString)
    .UseSyntaxCircusSnakeCaseNamingConvention();

Your own tables and columns still use snake_case. EF's history table keeps its default table and column names. On a newly created history table, the primary key constraint name is still snake_cased.

The wrapper replaces EF's history repository with one that sets those names explicitly. A commenter on issue #1 shared the same kind of workaround in 2021, so credit for the idea belongs in that thread.

If you want an affected database back on the default names, rename the columns first:


ALTER TABLE "__EFMigrationsHistory"
    RENAME COLUMN migration_id TO "MigrationId";

ALTER TABLE "__EFMigrationsHistory"
    RENAME COLUMN product_version TO "ProductVersion";

In one of my apps, the development database went back to the old names. I don't remember whether that change used a migration or a one-off script, so the SQL above is the version verified in the repro. After that rename, EF could read the migration history with the wrapper in place. Back up anything you care about, and coordinate the rename with the configuration change.

2. Keep the database and tell EF to match

In another app, the fix left the database as it was and configured EF to match it. A mixed naming style isn't pretty, but changing a deployed history table has its own risk.

If you stay on the raw UseSnakeCaseNamingConvention(), the existing snake_case columns already match what EF expects. However, if you use the wrapper as your usual configuration, you can override its choice for this database. The following repository does that by explicitly mapping the history columns to their deployed names, and it was verified in the repro:


#pragma warning disable EF1001 // internal Npgsql API
public sealed class HybridHistoryRepository(HistoryRepositoryDependencies dependencies)
    : NpgsqlHistoryRepository(dependencies)
{
    protected override void ConfigureTable(EntityTypeBuilder<HistoryRow> history)
    {
        base.ConfigureTable(history);

        history.ToTable("__EFMigrationsHistory");
        history.Property(row => row.MigrationId).HasColumnName("migration_id");
        history.Property(row => row.ProductVersion).HasColumnName("product_version");
    }
}
#pragma warning restore EF1001

Register it after the wrapper, so your replacement wins:


options.UseNpgsql(connectionString)
    .UseSyntaxCircusSnakeCaseNamingConvention()
    .ReplaceService<IHistoryRepository, HybridHistoryRepository>();

3. Use snake_case for the whole history table

If the mixed names bother you as much as they bother me, you can rename the table and columns. You'll need to configure both names so EF knows where to find its history:


options.UseNpgsql(connectionString, npgsql =>
        npgsql.MigrationsHistoryTable("__ef_migrations_history"))
    .UseSyntaxCircusSnakeCaseNamingConvention()
    .ReplaceService<IHistoryRepository, SnakeCaseHistoryRepository>();

MigrationsHistoryTable() sets the table name. SnakeCaseHistoryRepository sets the column names. With only the repository, the table remains __EFMigrationsHistory.

For an existing database, you also need to rename its table and any columns that don't match yet. Microsoft's custom migrations history table documentation says that updating an existing table is your job.

The trade-off with a custom history repository

Changing the table name uses a public EF Core setting. Changing column names means replacing IHistoryRepository, and these examples subclass NpgsqlHistoryRepository. That class is an internal API, which is why the compiler raises EF1001.

An EF Core or Npgsql upgrade could change it. Keep the warning suppression narrow, and add a test that reads a history table with your expected names. That way, you'll have something better than hope after an upgrade.

Apply the same configuration to your design-time context factory, if you have one. Otherwise, your migration tools and your running app can disagree about the history table.

What I'd check first

Before choosing an approach, check what names your database actually uses. Include the framework's tables when you look through the schema; they can be easy to overlook when you're concentrating on your own data. This query checks both history table names discussed here so you can compare the result with your configuration:


SELECT table_name, column_name
FROM information_schema.columns
WHERE table_name IN ('__EFMigrationsHistory', '__ef_migrations_history')
ORDER BY table_name, ordinal_position;

Once you know what's there, you can decide whether to keep those names or change them. Check each environment before making that choice, then coordinate any database changes with the configuration that will use them.

For me, this started as an irritation while looking at webhook data. Nothing had failed, and a mixed naming style can keep working as long as EF knows what to expect. The trouble comes when a configuration change makes EF look for names that aren't there, before it can even apply a migration to help you.

That's the distinction I'd keep in mind when deciding how much to change. You can leave a deployed history table alone and configure EF to match, or choose consistent snake_case names and make the changes together. Either way, knowing what your database already contains gives you a much better starting point than assuming the naming convention handled everything.

Cover photo by Tima Miroshnichenko on Pexels.

An unhandled error has occurred. Reload🗙