question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add-Migration fails to detect already applied migrations

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
creativesuspectscommented, Dec 6, 2021

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:

image

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?

0reactions
ajcvickerscommented, Apr 25, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Data migrations won't detect changes when adding new ...
After doing this, I should be able to create a new initial migration. But when i try to create create a new migration,...
Read more >
Add-Migration does not detect the change for Entity ...
It seems that the Entity Framework and the database is out of sync and I would need to run the Add-Migration and Update...
Read more >
EF - Add Migration Error - Microsoft Q&A
hi, I am trying to run Add-Migration command in PM. But I am getting an error add-migration : The term 'add-migration' is not...
Read more >
Migrations and Seed Data With Entity Framework Core
Using migrations is a standard way to create and update a database with Entity Framework Core. The migration process has two steps: Creating ......
Read more >
Entity Framework Core Migrations
The migrations feature in Entity Framework Core enables you to make changes to your model and then propagate those changes to your database ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found