I am adding a new migration but this message shows:
Unable to generate an explicit migration because the following explicit migrations are pending: [201203170856167_left]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
Can any one help me?
If you haven't used
Update-Database
you can just delete it. If you've run the update then roll it back usingUpdate-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?
It tells you that there is some unprocessed migration in your application and it requires running
Update-Database
before you can add another migration.Tip: It's always good to use the
-Script
switch for migration commands if you're not sure. It also really helps understand whatUpdate-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.
1. Connection String / Connection Permissions
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:
This connection string would go in the App.config file of the project where the DbContext is located.
2. StartUp Project
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.Had the same issue and was able to solve with some hints from above answers:
Use "update-database -verbose" in the package manager console to get more specific information where migrations tries to connect to. (Helped in my case to find out my startup proj was not set correctly...)
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.