How to re-create database for Entity Framework?

后端 未结 7 1186
野趣味
野趣味 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:10

    Follow below steps:

    1) First go to Server Explorer in Visual Studio, check if the ".mdf" Data Connections for this project are connected, if so, right click and delete.

    2 )Go to Solution Explorer, click show All Files icon.

    3) Go to App_Data, right click and delete all ".mdf" files for this project.

    4) Delete Migrations folder by right click and delete.

    5) Go to SQL Server Management Studio, make sure the DB for this project is not there, otherwise delete it.

    6) Go to Package Manager Console in Visual Studio and type:

    1. Enable-Migrations -Force
    2. Add-Migration init
    3. Update-Database

    7) Run your application

    Note: In step 6 part 3, if you get an error "Cannot attach the file...", it is possibly because you didn't delete the database files completely in SQL Server.

提交回复
热议问题