2016-11-13 108 views
0

我的代碼是這樣的找不到對象「dbo.Addresses」,因爲它不存在或您沒有權限

public class Address 
{ 
    public int Id { get; set; } 
    public string City { get; set; } 
    public int PostNo { get; set; } 
    public string Street { get; set; } 

} 

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public ApplicationDbContext() 
     : base("DefaultConnection", throwIfV1Schema: false) 
    { 
    } 

    public static ApplicationDbContext Create() 
    { 
     return new ApplicationDbContext(); 
    } 
    public System.Data.Entity.DbSet<MearnIt.Models.Address> Addresses { get; set; } 
    } 

當我運行NuGet包管理器控制檯上的更新,數據庫命令時,它hrows這個錯誤。

Cannot find the object "dbo.Addresses" because it does not exist or you do not have permissions. 

我不知道爲什麼它會拋出這樣的錯誤。任何人都可以指出herE出了什麼問題嗎?

+0

異常告訴你檢查兩件事情。首先在遷移連接到的數據庫*上執行*。 –

回答

1

嘗試的命令行:

打開文件瀏覽器並瀏覽到該文件夾​​爲您的項目(SRC文件夾內)。按住在鍵盤上的Shift,並在同一時間用鼠標右鍵單擊文件資源管理器,選擇「打開命令窗口在這裏」

的命令窗口應該出現。現在,輸入以下命令:

dotnet ef migrations add Initial. 

等待命令執行完畢。隨後進入:

donet ef database update 

記住要進行更改的數據庫,你將需要刪除Initial.cs在數據/文件夾遷移文件以前運行命令。現在再次運行這些命令。

希望有所幫助。

相關問題