locked
Re-create tables in Web-API RRS feed

  • Question

  • User-703842209 posted

    I have a Web-API which stores data in a MS SQL Database. Unfortunately, I accidentally deleted the database. Now when I try to register a user, it throws an exception saying "Invalid Object name AspNetUsers".

    Obviously the table doesn't exist thats why.

    How can I make the web-api re-create the tables which web-api creates by default when we start a new web-api project.

    Monday, June 20, 2016 9:53 PM

Answers

  • User36583972 posted

    Hi samirsyed,

    How can I make the web-api re-create the tables which web-api creates by default when we start a new web-api project.

    You may use Code First Migrations in EF to  re-create the database. Mainly the following three commands.

    Enable-Migrations
    Add-Migration Initial
    Update-Database
    

    Please refer to the following detailed tutorial.

    Use Code First Migrations to Seed the Database:

    http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-3

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 21, 2016 2:32 AM