Saturday, January 24, 2015

MVC - Unable to Attach DB

If you are working in Visual Studio, sometimes you want to try and start again with the database. Often this is when you make drastic model changes. I have on a number of occasions have deleted the .mdf file in the App_Data folder.

This is not a recommended approach, since it will cause inconsistencies with the connected database. To resolve this, open up the Package Manager Console and type in the following commands:

sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
Add-Migration MyMigration
Update-Database


When you do Update-Database, you may need to create a migration using Add-Migration <name>.

I've updated it to include this with the migration, please note that MyMigration can be anything that you want to call it.

Hope this helps.

0 comments:

Post a Comment