2016-11-13 126 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在数据/文件夹迁移文件以前运行命令。现在再次运行这些命令。

希望有所帮助。

相关问题