How to re-create database for Entity Framework?

后端 未结 7 1140
野趣味
野趣味 2020-11-30 16:18

I have got into a bad state with my ASP.Net MVC 5 project, using Code-First Entity Framework. I don\'t care about losing data, I just want to be able to start fresh, recreat

7条回答
  •  既然无缘
    2020-11-30 17:14

    I would like to add that Lin's answer is correct.

    If you improperly delete the MDF you will have to fix it. To fix the screwed up connections in the project to the MDF. Short answer; recreate and delete it properly.

    1. Create a new MDF and name it the same as the old MDF, put it in the same folder location. You can create a new project and create a new mdf. The mdf does not have to match your old tables, because were going to delete it. So create or copy an old one to the correct folder.
    2. Open it in server explorer [double click the mdf from solution explorer]
    3. Delete it in server explorer
    4. Delete it from solution explorer
    5. run update-database -force [Use force if necessary]

    Done, enjoy your new db

    UPDATE 11/12/14 - I use this all the time when I make a breaking db change. I found this is a great way to roll back your migrations to the original db:

    • Puts the db back to original
    • Run the normal migration to put it back to current

      1. Update-Database -TargetMigration:0 -force [This will destroy all tables and all data.]
      2. Update-Database -force [use force if necessary]

提交回复
热议问题