【问题标题】:Repopulate Database with table generated from model使用从模型生成的表重新填充数据库
【发布时间】:2013-06-02 23:02:46
【问题描述】:

我的一位同事不小心从我的数据库中删除了 UserProfiles 表,该表是从模型类生成的。

模型类如下所示:

namespace OneMillion.Models
{
    [Table("UserProfile")]
    public class User
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
        public string Sex { get; set; }
        public string SecretQuestion { get; set; }
        public string SecretQuestionAnswer { get; set; }
        public int MoneyIn { get; set; }
        public int MoneyOut { get; set; }
        public int TimesWon { get; set; }
    }
}

当我尝试通过包管理器控制台更新数据库时,我收到此错误:

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

数据迁移已启用。 我该如何解决这个问题?我要删除整个数据库吗?

【问题讨论】:

    标签: asp.net sql asp.net-mvc asp.net-mvc-4 model


    【解决方案1】:

    您能否以具有创建数据库的足够权限的用户身份连接到数据库?您可以在 SSMS 中以该用户身份登录并使用适当的列等创建表。然后该表存在,迁移可以找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多