From fd389e3e2e11eddac296ca6f8d5b01d50a904cc2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Aug 2026 02:01:56 +0000 Subject: [PATCH 1/3] Initial plan From 08fce58272c3df39d1bba305a336465c226bf92c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Aug 2026 02:05:40 +0000 Subject: [PATCH 2/3] Document ef6.exe migration utility Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .openpublishing.redirection.json | 5 + .../modeling/code-first/migrations/ef6-exe.md | 101 ++++++++++++++++++ .../code-first/migrations/migrate-exe.md | 91 ---------------- .../modeling/code-first/migrations/teams.md | 7 ++ .../ef6/what-is-new/past-releases.md | 2 +- entity-framework/toc.yml | 4 +- 6 files changed, 116 insertions(+), 94 deletions(-) create mode 100644 entity-framework/ef6/modeling/code-first/migrations/ef6-exe.md delete mode 100644 entity-framework/ef6/modeling/code-first/migrations/migrate-exe.md diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 175082dbbf..fe15eb3784 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -140,6 +140,11 @@ "redirect_url": "/ef/ef6/what-is-new/index", "redirect_document_id": false }, + { + "source_path": "entity-framework/ef6/modeling/code-first/migrations/migrate-exe.md", + "redirect_url": "/ef/ef6/modeling/code-first/migrations/ef6-exe", + "redirect_document_id": true + }, { "source_path": "entity-framework/core/get-started/aspnetcore/existing-db.md", "redirect_url": "/aspnet/core/data/ef-rp/intro", diff --git a/entity-framework/ef6/modeling/code-first/migrations/ef6-exe.md b/entity-framework/ef6/modeling/code-first/migrations/ef6-exe.md new file mode 100644 index 0000000000..e1e1c2751c --- /dev/null +++ b/entity-framework/ef6/modeling/code-first/migrations/ef6-exe.md @@ -0,0 +1,101 @@ +--- +title: Using ef6.exe - EF6 +description: Using ef6.exe in Entity Framework 6 +author: SamMonoRT +ms.date: 08/19/2026 +uid: ef6/modeling/code-first/migrations/ef6-exe +--- +# Using ef6.exe + +> [!NOTE] +> This article assumes you know how to use Code First Migrations in basic scenarios. If you don't, then read [Code First Migrations](xref:ef6/modeling/code-first/migrations/index) before continuing. + +Code First Migrations can update a database from Visual Studio, but you can also run migrations from the command line with `ef6.exe`. This utility replaces `migrate.exe`. + +## Locate ef6.exe + +When you install Entity Framework using NuGet, `ef6.exe` is in the tools folder of the NuGet package. With PackageReference, the package is stored in the global packages folder. For example: + +```text +%USERPROFILE%\.nuget\packages\entityframework\6.4.4\tools\net45\win-x86\ef6.exe +``` + +Replace `6.4.4` with the version of Entity Framework installed in your project. + +## View the options + +```console +ef6.exe database update --help +``` + +## Migrate to the latest migration + +```console +ef6.exe database update --assembly MyMvcApplication.dll --config ..\web.config +``` + +The assembly containing the migrations is required. Other settings use conventions when they aren't specified. + +## Migrate to a specific migration + +```console +ef6.exe database update --assembly MyApp.exe --config MyApp.exe.config --target AddTitle +``` + +Use `--target` to apply all migrations through a specific migration. + +## Specify working directory + +```console +ef6.exe database update --assembly MyApp.exe --config MyApp.exe.config --project-dir C:\MyApp +``` + +Use `--project-dir` when the assembly has dependencies or reads files relative to the project directory. + +## Specify migration configuration to use + +```console +ef6.exe database update --assembly MyAssembly.dll --migrations-config CustomConfig --config ..\web.config +``` + +If the assembly contains multiple migration configuration classes, use `--migrations-config` to specify which one to use. + +## Provide connection string + +```console +ef6.exe database update --assembly BlogDemo.dll --connection-string "Data Source=localhost;Initial Catalog=BlogDemo;Integrated Security=SSPI" --connection-provider System.Data.SqlClient +``` + +When you specify a connection string, you must also specify its provider name. + +## Generate a SQL script + +Use `--script` to write the SQL migration script to standard output. Redirect the output to save the script to a file: + +```console +ef6.exe database update --assembly MyApp.dll --script > migration.sql +``` + +Use `--source` and `--target` to control the range of migrations included in the script. + +## migrate.exe option equivalents + +The following table maps `migrate.exe` arguments to their `ef6.exe database update` equivalents: + +| migrate.exe | ef6.exe database update | +| --- | --- | +| `` | `--assembly` | +| `` | `--migrations-config` | +| `` | No equivalent. Put it in the same directory as the assembly passed to `--assembly`. | +| `/targetMigration` | `--target` | +| `/startUpDirectory` | `--project-dir` | +| `/scriptFile` | `--script` | +| `/sourceMigration` | `--source` | +| `/startUpConfigurationFile` | `--config` | +| `/startUpDataDirectory` | `--data-dir` | +| `/connectionStringName` | `--connection-string-name` | +| `/connectionString` | `--connection-string` | +| `/connectionProviderName` | `--connection-provider` | +| `/force` | `--force` | +| `/verbose` | `--verbose` | +| `/?` | `--help` | diff --git a/entity-framework/ef6/modeling/code-first/migrations/migrate-exe.md b/entity-framework/ef6/modeling/code-first/migrations/migrate-exe.md deleted file mode 100644 index f628550328..0000000000 --- a/entity-framework/ef6/modeling/code-first/migrations/migrate-exe.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: Using migrate.exe - EF6 -description: Using migrate.exe in Entity Framework 6 -author: SamMonoRT -ms.date: 10/23/2016 -uid: ef6/modeling/code-first/migrations/migrate-exe -ms.custom: sfi-ropc-nochange ---- -# Using migrate.exe -Code First Migrations can be used to update a database from inside visual studio, but can also be executed via the command line tool migrate.exe. This page will give a quick overview on how to use migrate.exe to execute migrations against a database. - -> [!NOTE] -> This article assumes you know how to use Code First Migrations in basic scenarios. If you don’t, then you’ll need to read [Code First Migrations](xref:ef6/modeling/code-first/migrations/index) before continuing. - -## Copy migrate.exe - -When you install Entity Framework using NuGet migrate.exe will be inside the tools folder of the downloaded package. In <project folder>\\packages\\EntityFramework.<version>\\tools - -Once you have migrate.exe then you need to copy it to the location of the assembly that contains your migrations. - -If your application targets .NET 4, and not 4.5, then you will need to copy the **Redirect.config** into the location as well and rename it **migrate.exe.config**. This is so that migrate.exe gets the correct binding redirects to be able to locate the Entity Framework assembly. - -| .NET 4.5 | .NET 4.0 | -|:----------------------------------------------|:----------------------------------------------| -| ![.NET 4.5 Files](~/ef6/media/net45files.png) | ![.NET 4.0 Files](~/ef6/media/net40files.png) | - -> [!NOTE] -> migrate.exe doesn't support x64 assemblies. - -Once you have moved migrate.exe to the correct folder then you should be able to use it to execute migrations against the database. All the utility is designed to do is execute migrations. It cannot generate migrations or create a SQL script. - -## See options - -``` console -Migrate.exe /? -``` - -The above will display the help page associated with this utility, note that you will need to have the EntityFramework.dll in the same location that you are running migrate.exe in order for this to work. - -## Migrate to the latest migration - -``` console -Migrate.exe MyMvcApplication.dll /startupConfigurationFile="..\\web.config" -``` - -When running migrate.exe the only mandatory parameter is the assembly, which is the assembly that contains the migrations that you are trying to run, but it will use all convention based settings if you do not specify the configuration file. - -## Migrate to a specific migration - -``` console -Migrate.exe MyApp.exe /startupConfigurationFile="MyApp.exe.config" /targetMigration="AddTitle" -``` - -If you want to run migrations up to a specific migration, then you can specify the name of the migration. This will run all previous migrations as required until getting to the migration specified. - -## Specify working directory - -``` console -Migrate.exe MyApp.exe /startupConfigurationFile="MyApp.exe.config" /startupDirectory="c:\\MyApp" -``` - -If you assembly has dependencies or reads files relative to the working directory then you will need to set startupDirectory. - -## Specify migration configuration to use - -``` console -Migrate.exe MyAssembly CustomConfig /startupConfigurationFile="..\\web.config" -``` - -If you have multiple migration configuration classes, classes inheriting from DbMigrationConfiguration, then you need to specify which is to be used for this execution. This is specified by providing the optional second parameter without a switch as above. - -## Provide connection string - -``` console -Migrate.exe BlogDemo.dll /connectionString="Data Source=localhost;Initial Catalog=BlogDemo;Integrated Security=SSPI" /connectionProviderName="System.Data.SqlClient" -``` - -If you wish to specify a connection string at the command line then you must also provide the provider name. Not specifying the provider name will cause an exception. - -## Common Problems - -| Error Message | Solution | -|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) | This typically means that you are running a .NET 4 application without the Redirect.config file. You need to copy the Redirect.config to the same location as migrate.exe and rename it to migrate.exe.config. | -| Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) | This exception means that you are running a .NET 4.5 application with the Redirect.config copied to the migrate.exe location. If your app is .NET 4.5 then you do not need to have the config file with the redirects inside. Delete the migrate.exe.config file. | -| ERROR: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. | This error occurs if running migrate when you haven’t created a migration to cope with changes made to the model, and the database does not match the model. Adding a property to a model class then running migrate.exe without creating a migration to upgrade the database is an example of this. | -| ERROR: Type is not resolved for member 'System.Data.Entity.Migrations.Design.ToolingFacade+UpdateRunner,EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. | This error can be caused by specifying an incorrect startup directory. This must be the location of migrate.exe | -| Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.Migrations.Console.Program.Main(String[] args) | This can be caused by not specifying a required parameter for a scenario that you are using. For example specifying a connection string without specifying the provider name. | -| ERROR: More than one migrations configuration type was found in the assembly 'ClassLibrary1'. Specify the name of the one to use. | As the error states, there is more than one configuration class in the given assembly. You must use the /configurationType switch to specify which to use. | -| ERROR: Could not load file or assembly ‘<assemblyName>’ or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) | This can be caused by specifying an assembly name incorrectly or not having | -| ERROR: Could not load file or assembly ‘<assemblyName>' or one of its dependencies. An attempt was made to load a program with an incorrect format. | This happens if you are trying to run migrate.exe against an x64 application. EF 5.0 and below will only work on x86. | diff --git a/entity-framework/ef6/modeling/code-first/migrations/teams.md b/entity-framework/ef6/modeling/code-first/migrations/teams.md index a57e493aae..39de43f708 100644 --- a/entity-framework/ef6/modeling/code-first/migrations/teams.md +++ b/entity-framework/ef6/modeling/code-first/migrations/teams.md @@ -29,6 +29,13 @@ The bottom line is that automatic migrations initially look good in team environ Automatic migrations allows you to have your database schema updated to match the current model without the need to generate code files (code-based migrations). Automatic migrations would work very well in a team environment if you only ever used them and never generated any code-based migrations. The problem is that automatic migrations are limited and don’t handle a number of operations – property/column renames, moving data to another table, etc. To handle these scenarios you end up generating code-based migrations (and editing the scaffolded code) that are mixed in between changes that are handled by automatic migrations. This makes it near on impossible to merge changes when two developers check in migrations. +## Screencasts + +If you'd rather watch screencasts than read this article, the following videos cover the same content: + +- [Migrations - Under the Hood](https://learn.microsoft.com/shows/ef/migrations-under-hood) explains how migrations track and use model information to detect changes. +- [Migrations - Team Environments](https://learn.microsoft.com/shows/ef/migrations-team-environments) explains the issues that arise in a team environment and how to solve them. + ## Understanding how migrations works The key to successfully using migrations in a team environment is a basic understanding how migrations tracks and uses information about the model to detect model changes. diff --git a/entity-framework/ef6/what-is-new/past-releases.md b/entity-framework/ef6/what-is-new/past-releases.md index fc52492e0d..53855ec3e2 100644 --- a/entity-framework/ef6/what-is-new/past-releases.md +++ b/entity-framework/ef6/what-is-new/past-releases.md @@ -173,7 +173,7 @@ Here is a list of content we put together specifically for the EF 5 release: - [Fluent API with VB.NET](xref:ef6/modeling/code-first/fluent/vb) - [Code First Migrations](xref:ef6/modeling/code-first/migrations/index) - [Automatic Code First Migrations](xref:ef6/modeling/code-first/migrations/automatic) - - [Migrate.exe](xref:ef6/modeling/code-first/migrations/migrate-exe) + - [ef6.exe](xref:ef6/modeling/code-first/migrations/ef6-exe) - [Defining DbSets](xref:ef6/modeling/code-first/dbsets) - EF Designer - [Model First (walkthrough and video)](xref:ef6/modeling/designer/workflows/model-first) diff --git a/entity-framework/toc.yml b/entity-framework/toc.yml index 884ae792ee..dc880e2309 100644 --- a/entity-framework/toc.yml +++ b/entity-framework/toc.yml @@ -636,8 +636,8 @@ href: ef6/modeling/code-first/migrations/existing-database.md - name: Customize Migrations history href: ef6/modeling/code-first/migrations/history-customization.md - - name: Use Migrate.exe - href: ef6/modeling/code-first/migrations/migrate-exe.md + - name: Use ef6.exe + href: ef6/modeling/code-first/migrations/ef6-exe.md - name: Migrations in team environments href: ef6/modeling/code-first/migrations/teams.md - name: Use EF Designer From b3c0591029fd3ecf5b1f0e0c4be2189f699508bc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 01:15:23 +0000 Subject: [PATCH 3/3] Revert teams screencast links Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../ef6/modeling/code-first/migrations/teams.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/entity-framework/ef6/modeling/code-first/migrations/teams.md b/entity-framework/ef6/modeling/code-first/migrations/teams.md index 39de43f708..a57e493aae 100644 --- a/entity-framework/ef6/modeling/code-first/migrations/teams.md +++ b/entity-framework/ef6/modeling/code-first/migrations/teams.md @@ -29,13 +29,6 @@ The bottom line is that automatic migrations initially look good in team environ Automatic migrations allows you to have your database schema updated to match the current model without the need to generate code files (code-based migrations). Automatic migrations would work very well in a team environment if you only ever used them and never generated any code-based migrations. The problem is that automatic migrations are limited and don’t handle a number of operations – property/column renames, moving data to another table, etc. To handle these scenarios you end up generating code-based migrations (and editing the scaffolded code) that are mixed in between changes that are handled by automatic migrations. This makes it near on impossible to merge changes when two developers check in migrations. -## Screencasts - -If you'd rather watch screencasts than read this article, the following videos cover the same content: - -- [Migrations - Under the Hood](https://learn.microsoft.com/shows/ef/migrations-under-hood) explains how migrations track and use model information to detect changes. -- [Migrations - Team Environments](https://learn.microsoft.com/shows/ef/migrations-team-environments) explains the issues that arise in a team environment and how to solve them. - ## Understanding how migrations works The key to successfully using migrations in a team environment is a basic understanding how migrations tracks and uses information about the model to detect model changes.