0
我試圖在添加需要在數據庫中的表的幾個類後更新我的數據庫。嘗試更新時出錯 - 數據庫代碼優先
,我發現了以下錯誤:
There is already an object named 'Blogs' in the database.
我的數據上下文這個樣子的(3最後一行是我需要添加到我的數據庫表):
public class WowDataContext : DbContext
{
public WowDataContext()
: base("name=DefaultConnection")
{ }
public DbSet<Genre> Ganres { get; set; }
public DbSet<TakeAway> TaKeAways { get; set; }
public DbSet<Gellery> Galleries { get; set; }
public DbSet<katering> Katring { get; set; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Events> events { get; set; }
//i need to add this folowing 3 tables
public DbSet<Order> orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
public DbSet<Cart> Carts { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
的孔更新Db的是這樣的:
[http://pastebin.com/CTwbz6Wj1
和我的數據庫遷移看起來像這樣圖片 [遷移表] [2]`
您需要運行update-database命令。 http://stackoverflow.com/questions/18308831/how-to-update-model-and-database-with-code-first-approach-in-asp-net-mvc – Brian
是的,我已經嘗試過,我也重新運行此:添加遷移201403251531583_InitialCreate 重新腳手架遷移'201403251531583_InitialCreate'。 只有設計器代碼遷移'201403251531583_InitialCreate'被重新腳手架。要重新搭建整個遷移,請使用-Force參數..它沒有幫助 – Danny