Reputation: 6896
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?
Upvotes: 0
Views: 7127
Reputation: 25
Firstly try these please :
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.
Upvotes: -2
Reputation: 2800
Remove the Migrations folder in your project
Delete the _MigrationHistory
table from your database.
Enable-Migrations
command from your Package Manager Console.Add-Migration Init
command to create a migration.Up()
function for the initial migration. (To create an empty migration and solve the errors that you are facing.)Update-Database
command to apply your empty migration.Add-Migration InitNew
command to create a new migration.Update-Database
command to apply the changes.Upvotes: 3