我的同事不小心从我的数据库中删除了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.
启用数据迁移。 我怎么解决这个问题?我要删除整个数据库吗?
答案 0 :(得分:0)
您是否可以作为具有足够权限创建数据库的用户连接到数据库?您可以在SSMS中以该用户身份登录,并使用相应的列等创建表。然后该表存在,并且迁移可以找到它。