a blog for those who code

Wednesday 12 April 2017

How to solve Unable to update database in ASP.NET MVC

In this post we will be discussing about solving Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration in in ASP.NET MVC 5 when used with Entity Framework.

Lets say you have created a model to the existing database and then you want to update the database to reflect the new changes. When you type Update-Database you will get the below error.


Code-First Migration in Entity Framework has two important commands and they are :

1. Add-Migration : It will scaffold the next migration for the changes you have made to your domain classes.
2. Update-Database: It will apply pending changes to the database based on latest scaffolding colde file you have created using 'Add-Migration' command.

To solve this error we need to scaffold the next migration for the changes using the command Add-Migration as shown below :


Next we will again run the command Update-Database which will update the database as per your new models.


Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment