"how to re-create database for entity framework?" Code Answer


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.

By noloader on July 16 2022

Answers related to “how to re-create database for entity framework?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.