Add-Migration fails to detect already applied migrations
See original GitHub issueI regularly get into the situation where I try to add a new migration, and get a message stating that the migration could not be created because previous migrations have not been applied to the database (they have). The problem resolves itself by simply closing and reopening Visual Studio, and running the Add-Migration
command again.
PM> Add-Migration MyMigration -Verbose
System.Data.Entity.Migrations.Infrastructure.MigrationsPendingException: Unable to generate an explicit migration because the following explicit migrations are pending: [… list of all migrations in the project …]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
Call stack:
at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The previous message lists all migrations in the project as needing to be applied, as if it were a new database (it is not).
At that point if I try to run Update-Database
, I get an error because the __MigrationHistory
table already exists.
Using Entity Frameowork 6.2.0 on .NET 4.5.
I would try to troubleshoot this but I’m not sure how to attach a debugger to the DbMigrator
class so that I can step through it?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
I’m having the same issue after upgrading from EF 6.4.0 to EF 6.4.4. I can’t add a new migration because EF says that none of the previous migrations have been applied:
This has nothing to do with Visual Studio, because I get the same error when I try to add a migration using the ef6.exe command line tool. Obviously I can’t run the “update database” command, because all the previous migrations have already been applied to the database and are visible in the __MigrationHistory table. So basically I’m stuck in limbo.
@hbopuri, @xps: Did you manage to fix this issue?
This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.