I am adding a new migration but this message shows:
Unable to generate an explicit migration because the following explicit migrations are pending:
If you haven't used Update-Database
you can just delete it. If you've run the update then roll it back using Update-Database -TargetMigration "NameOfPreviousMigration"
, then delete it.
Reference: http://elegantcode.com/2012/04/12/entity-framework-migrations-tips/
I copied this text directly from here: How do I undo the last Add-Migration command?
I had the same problems and was only able to resolve it running Add-Migration 'MigrationName' -Force
With -Force being the important part.
Tip: It's always good to use the -Script
switch for migration commands if you're not sure. It also really helps understand what Update-Database
actually does.
I run the following to update the database, then I get a script I can apply manually (or just run it again without the -Script tag).
For Update-Database
I would run the following :
Update-Database -Script -ConfigurationTypeName Configuration_ASPNETIdentity -ConnectionStringName SQL_AzureLive
Where SQL_AzureLive
is the named connection string in my config.
Then I can verify the SQL looks right, apply it and be done. As many others have said if the connection string is wrong or invalid you'll get this error.
It tells you that there is some unprocessed migration in your application and it requires running Update-Database
before you can add another migration.
Scenario
Problem
After updating from master, I run "Add-Migration my_migration_name", but get the following error:
Unable to generate an explicit migration because the following explicit migrations are pending: [201607181944091_AddExternalEmailActivity]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
So, I run "Update-Database" and get the following error:
Unable to update database to match the current model because there are pending changes and automatic migration is disabled
Solution
At this point re-running "Add-Migration my_migration_name" solved my problem. My theory is that running "Update-Database" got everything in the state it needed to be in order for "Add-Migration" to work.
In my case (using MS Visual Studio), it was as simple as restarting Visual Studio.