Entity Framework Automatic Migrations Existing Database

后端 未结 3 1387
孤独总比滥情好
孤独总比滥情好 2021-01-13 20:51

I am building an ASP.Net MVC4 web application with Entity Framework 5. I had to use an existing sql server database but also wanted to use Code First, so I followed this tut

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 21:40

    if your context is mine: added a new entity class worked on it but, when I tried to migrate it shows this error, try removing that object from db context then run update-database and add that object again and rerun update-database

    for example:

    public DbSet CustomizedEmail { get; set; }
    public DbSet KeyWordsForEmail { get; set; }
    public DbSet Notice { get; set; }//remove it>run update-database>
    //add again the above entity and rerurn update-database
    

    this works whether you have data or not. in this process you will loose data in that table.

提交回复
热议问题