Why does EF 6 ignore applied migrations if I move the Migrations folder?

When I first started Enable-Migrationsin my project, he created a folder Migrationsin the root of the project. Then I moved the folder Migrationsto the folder Datawhere there is context and models, etc. Then I fixed the namespaces in both migrations already applied.

Then I tried a third migration with Add-Migration IdToLong, and I got an error message:

An explicit transition cannot be created because the following explicit migrations are expected: [201703061039495_Initial, 201703061159110_ContactRequest]. Applying pending explicit migrations before attempting to generate a new explicit migration.

The only reason I can think of this is because EF kept the relative path to the location of the connection string, and that path is now useless. I saw several reports that EF shows the same message when it is not possible to connect to the database.

This hidden storage / config for EF runs counter to the grain, where we are moving with EF Core, and I really hope this problem does not occur there.

To get to my question, what changed or didn't change when I moved Migrationsso that EF could no longer see that I already applied these migrations?

+4
source share
1 answer

() . ContextKey __MigrationHistory. , , EF , , .

, :

1) script, :

UPDATE [dbo].[__MigrationHistory] 
   SET [ContextKey] = 'New_Namespace.Migrations.Configuration'
 WHERE [ContextKey] = 'Old_Namespace.Migrations.Configuration'

2) :

public Configuration()
{
    AutomaticMigrationsEnabled = false;
    ContextKey = "Old_Namespace.Migrations.Configuration";
}
+3

Source: https://habr.com/ru/post/1671695/


All Articles