'Errors on Add-Migration
A few weeks ago I enabled migration on my project and added a column 'ClientID' to the AspNetUsers table.
Now I'm trying to add another column: "Name".
I ran this command in the Package Manager Console:
PM> Add-Migration "Name"
And I got the following error:
Unable to generate an explicit migration because the following explicit migrations are pending: [20161081751088_InitialCreate, 20161091825212_ClientID]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
I ran an update command:
PM> Update-Database
But:
There is already an object named 'AspNetRoles' in the database.
I researched online and found this solution:
PM> Add-Migration InitialMigrations -IgnoreChanges
But then I got the first error again:
Unable to generate an explicit migration because the following explicit migrations are pending: [20161081751088_InitialCreate, 20161091825212_ClientID]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
How can I solve this problem?
Solution 1:[1]
Firstly try these please :
- 1- clean the project up-root solution
- 2- close the visual studio
- 3- reopen vs and open the solution
- 4- build it.
- 5- totally remove the migrations folder under the entities folder
- 6- remove the table _projectnameMigrations from the DB
- 7- open the PMC in Vs
- 8- Enable-Migrations
- 9- Add-Migrations mig_Myinit
- 10- (!Important) clear the up method and make it empty
- 11- update-database
- 12- done
Your next migrations... point is that if you remove a table manually from the database Entity Framework is not able to recognize it and by default it is accessible so when you are using EF you have to do any database-related tasks from the pmc.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AFract |
