I am using Entity Framework 5.0 RC with the LocalDB database that comes pre-configured with VS 2012 RC for some prototyping and testing of code-first database.
After a few cycles of changing my code-first database and running "update-database" I did a huge breaking change and automatic migration failed bad. I don't care about resolving this conflict since this is just prototyping, so losing data is fine.
How do I reset or delete the database? Reset must also reset the migration table, which seems to be hidden from Server Explorer in Visual Studio.
In order to be deleted, first it should be stopped. Type the SqlLocalDB stop MSSQLLocaDB command in the Command Prompt window: LocalDB instance “MSSQLLocalDB” stopped. Now, repeat the SqlLocalDB delete MSSQLLocalDB command.
Right-click anywhere on the design surface, and select Update Model from Database. In the Update Wizard, select the Refresh tab and then select Tables > dbo > Student. Click Finish.
Drop the whole database in Visual Studio
So far this is the best approach I have found.
To alter __MigrationHistory table, see this article to handle both existing databases and new databases created with code-first.
The SQL script is as follows:
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?";
I am using Database .NET v4 Free to run this SQL script, because my Visual Studio 11 RC copy won't let me run queries on LocalDB for some reason. Also, I need to run the script twice for it to drop all tables due to some foreign keys. I haven't bothered fixing this since it seems to work well enough as it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With