What happened ?
I was trying to do an entity migration using Package Manager console in Visual Studio for my newly edited entities. But while I was executing ‘update-database
‘ command with ‘-verbose
‘ flag, it throwed an error and update had failed. After I fix the error in the entity, I was trying to run ‘add-migration
‘ again with a new name, however it has failed again with a different error like below,
PM> add-migration v0.19.1
Unable to generate an explicit migration because the following explicit migration are pending: [202105011049565_v0.19]. Apply the pending explicit migrations before attempting to generate a new explicit migration
PM>
Solution
Reason for the issue is that I was trying to add a new migration without removing previous migration which was not succeed earlier.
You can easily overcome this issue by renaming your last migration class and re executing ‘add-migration
‘ command with a different name in Package Manager Console, where it will create a new file with your latest changes. Later, you can execute ‘Update-database -TargetMigration {your-new-migration-name} -verbose
‘.
Note: After create a new migration file, do not rename you faulty migration file to same name again. Because when you are running Update-database
command, it will add you faulty migration again into the execution queue.
Happy Coding!