How to delete and recreate from scratch an existing EF Code First database

If I’m understanding it right…

If you want to start clean:

1) Manually delete your DB – wherever it is (I’m assuming you have your connection sorted), or empty it, but easier/safer is to delete it all together – as there is system __MigrationHistory table – you need that removed too.

2) Remove all migration files – which are under Migrations – and named like numbers etc. – remove them all,

3) Rebuild your project containing migrations (and the rest) – and make sure your project is set up (configuration) to build automatically (that sometimes may cause problems – but not likely for you),

4) Run Add-Migration Initial again – then Update-Database

Leave a Comment