【问题标题】:Cannot find the object "dbo.Addresses" because it does not exist or you do not have permissions找不到对象“dbo.Addresses”,因为它不存在或您没有权限
【发布时间】:2016-11-13 06:49:04
【问题描述】:

我的代码是这样的

 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 包管理器控制台上运行 Update-Database 命令时,它会抛出此错误。

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

我不知道为什么会抛出这样的错误。谁能指出这里出了什么问题?

【问题讨论】:

  • 异常告诉你检查两件事。首先在迁移连接到的数据库上执行此操作

标签: asp.net-mvc entity-framework nuget-package


【解决方案1】:

试试命令行:

打开 文件资源管理器 并浏览到您的项目的文件夹(在 src 文件夹中)。按住键盘上的shift,同时右键单击文件资源管理器并选择“在此处打开命令窗口”

应该会出现一个命令窗口。现在,输入以下命令:

dotnet ef migrations add Initial.

等到命令执行完毕。接着输入:

donet ef database update

请记住,为了对数据库进行更改,您需要在运行命令之前 删除 Data/Migrations 文件夹中的 Initial.cs 文件。现在再次运行命令。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-11-22
    • 2015-05-27
    • 2010-12-08
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 2013-04-09
    相关资源
    最近更新 更多