Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 1.53 KB

File metadata and controls

34 lines (24 loc) · 1.53 KB
title description author ms.date uid
Custom Migrations History Table - EF Core
Customizing a history table to use for migrations with Entity Framework Core
bricelam
11/07/2017
core/managing-schemas/migrations/history-table

Custom Migrations History Table

By default, EF Core keeps track of which migrations have been applied to the database by recording them in a table named __EFMigrationsHistory. For various reasons, you may want to customize this table to better suit your needs.

Important

If you customize the Migrations history table after applying migrations, you are responsible for updating the existing table in the database.

Schema and table name

You can change the schema and table name using the MigrationsHistoryTable() method in OnConfiguring() (or ConfigureServices() on ASP.NET Core). Here is an example using the SQL Server EF Core provider.

[!code-csharpMain]

Other changes

To configure additional aspects of the table, override and replace the provider-specific IHistoryRepository service. Here is an example of changing the MigrationId column name to Id on SQL Server.

[!code-csharpMain]

Warning

SqlServerHistoryRepository is inside an internal namespace and may change in future releases.

[!code-csharpMain]