Troubleshoot Add-Migration Error: Migrations are Pending

Problem:

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: …

Solution:

There are multiple causes/fixes:

  1. Most of the time, it is because one forgets to do the “update database” with pending migration scripts.
  2. In Package Manager Console, select the correct Default project.  It should be the project with the database model.
  3. In Solution Explorer, verify the correct startup project is selected.  The project name should be in bold font.
  4. In app.config of the startup project, check the connection string to make sure the right database is being checked against.
  5. 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
  6. When all else fails, you can explicit set it:

add-migration [migrationScriptName] –ConfigurationTypeName [ConfigurationClassName] –StartUpProject [startupProjectName] –ConnectionStringName [ConnectionName]

Reference:

https://stackoverflow.com/questions/9817860/unable-to-generate-an-explicit-migration-in-entity-framework

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s