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 the same problem. Apparently entity framework generates this error when it's unable to connect to the database. So make sure that you're able to access it before searching for other problems.
This error means there are pending migrations need to be commited before you can execute another explicit migration. You can choose to
After this one you can start "Add-Migration ..." again
Hope it helps
I also came across this issue. It came when I created new DB and I had pending changes for my code-first DB migration then I tried to run "Update-Database" command. Solution : Run "Add-Migration -MigrationName" command to create new migration for new DB. Then run "Update-Database" command.
Historically I always solved this by deleting the pending migrations, or if there was only 1 remaining and it was mostly desirable, by using -f
to recreate it.
Recently, this has stopped working for me.
When this happened the first time, I restarted Visual Studio, and then it let me proceed.
The second time, it only worked after I ran a Clean on the project. It was almost as if the pending migrations were retained despite deleting all the files from explorer.
Check the connection string again.
Make sure the user you are connecting with still has permission to read from [__MigrationHistory]
and has permission to edit the schema.
You can also try changing the connection string in the App or Web config file to use Integrated Security (Windows Auth) to run the add-migration command as yourself.
For example:
connectionString="data source=server;initial catalog=db;persist security info=True;Integrated Security=SSPI;"
This connection string would go in the App.config file of the project where the DbContext is located.
You can specify the StartUp project on the command line or you can right click the project with the DbContext
, Configuration
and Migrations folder and select Set as StartUp project. I'm serious, this can actually help.
For me, i deleted the migration file(in your case "201203170856167_left") from Migrations
folder, and then ran the below command in Package Manager console
Add-Migration <Parameter>
Update-Database