【发布时间】:2015-05-14 18:09:33
【问题描述】:
我目前收到一个错误我理解错误但我不知道我哪里出错了
ALTER TABLE 语句与 FOREIGN KEY 约束“FK_dbo.AspNetUsers_dbo.CompanyDetails_userCompanyID”冲突。冲突发生在数据库“PXWHITESPIDERDEV”、表“dbo.CompanyDetails”、列“companyID”中。
在您创建 MVC 应用程序时自动生成的 IdentityModel 中
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public int userCompanyID { get; set; }
[ForeignKey("userCompanyID")]
public CompanyDetails company { get; set; }
}
这是我要创建的实体
public class CompanyDetails
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int companyID { get; set; }
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 1)]
[Display(Name = "Company Name")]
public string CompanyName { get; set; }
}
在 RegisterViewModel 类中
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public CompanyDetails company { get; set; }
}
在 ApplicationUser 类和 CompanyDetails 类中的 companyID 相同之前,它们具有相同的变量名。我认为这是问题所在,因此更改了 ApplicationUser 类中的变量名,直到我再次尝试更新数据库并发现情况并非如此。
【问题讨论】:
标签: c# entity-framework asp.net-mvc-5 asp.net-identity