When I try to do an “add-migration”, I get the following error:
Unable to generate an explicit migration because the following explicit migrations are pending: …
There are multiple causes/fixes:
- Most of the time, it is because one forgets to do the “update database” with pending migration scripts.
- In Package Manager Console, select the correct Default project. It should be the project with the database model.
- In Solution Explorer, verify the correct startup project is selected. The project name should be in bold font.
- In app.config of the startup project, check the connection string to make sure the right database is being checked against.
- Check the __MigrationHistory database in the target database. Check the value of the column “ContextKey”. It should be the same as the class name in Migrations/Configuration.cs.
- When all else fails, you can explicit set it:
add-migration [migrationScriptName] –ConfigurationTypeName [ConfigurationClassName] –StartUpProject [startupProjectName] –ConnectionStringName [ConnectionName]