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?
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.