EntityFramework 7 database already exists error on migrations

asp.net-core entity-framework-core

Question

ASP.NET 5 project, Entity Framework 7. Using all the default stuff that comes with the ASP.NET 5 web template for creating the Identity Context. When I start up the app and first try to hit the context (register or log in), there is an error on Database.AsRelational().ApplyMigrations() that the database already exists. However, when I connect to the database matching the connection string in config.json, I do not see the database.

"ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=aspnet-myAppDb;Trusted_Connection=True;MultipleActiveResultSets=true"

enter image description here

enter image description here

Accepted Answer

Connect to (localdb)\mssqllocaldb in SQL Server Management Studio, delete the database there. I'm not sure why this step is required or why the migrations fails, however.


Popular Answer

There is an already accepted answer, but I prefer doing this from Visual Studio. This is caused by manually deleting the MDB file. For future reference, you should not delete the MDB files from Explorer, but instead use Visual Studio or SQL Server Management Studio to delete them.

In Visual Studio, hit Ctrl+\, Ctrl+S to bring up SQL Server Object Explorer. If your keybindings are different, look under the View Menu.

Expand the node for the type of localdb you are using, find your problem database, right click and delete. Problem fixed.

Delete LocalDb



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why