I am adding a new migration but this message shows:
Unable to generate an explicit migration because the following explicit migrations are pending:
I had a simpler problem. VS erroneously reported this error when I had a VPN connection to a client's site connected on my workstation. The problem was that the DBMS security was set to accept requests only from my real local IP. Simply turning off the VPN resolved the problem.
You either need to run "update-database" from the package manager console to push your changes to the database OR you can delete the pending migration file ([201203170856167_left]) from your Migrations folder and then re-run "add-migration" to create a brand new migration based off of your edits.
When running into this issue, please try adding parameters to your add-migration cmdlet. For example, specifying the start up project as well as the connection string name could help EF find your target database.
add-migration Delta_Defect_0973 -ConfigurationTypeName your.namespace.ContextClassName -StartUpProject DeltaProject -ConnectionStringName DeltaSQL
Where:
Delta_Defect_0973 is the name of your migration
your.namespace.ContextClassName is the name of your Configuration class in your migration folder, prefixed with the full name space.
DeltaProject is the name of your main project with your web.config or app.config file.
DeltaSQL is the name of your connection string defined in your web.config or app.config file.
My local database did not have the __MigrationHistory
populated, or existing. I manually created the table, and then migrated the data in that table from PROD to my local database. This caused VS to think the migrations had been applied (which they had been).
Old post but might help someone.
For me it happened because I renamed Assembly name
and Default namespace
of the project.
So I had to update ContextKey
in _MigrationHisotry
table to the new value of Assembly name
or Default namespace
. Honestly I don't know which one should be used, because for me both are same!
There is an ambiguity and so error. Best way is to exclude the current migration file and create new migration(add-migration) file and then copy the content of new migration to excluded file and include it again and run update-database command.