我目前得到一个错误我理解的错误,但我不知道在哪里,我错了
ALTER TABLE语句冲突与外键约束“FK_dbo.AspNetUsers_dbo.CompanyDetails_userCompanyID”。 发生于数据库“PXWHITESPIDERDEV”,表“dbo.CompanyDetails”的冲突,列“companyID”。
内IdentityModel自动生成的,当你创建一个MVC应用程序
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; }
}
前companyID的人的ApplicationUser类和CompanyDetails类中一样在他们有相同的变量名。 我认为这是问题的ApplicationUser类内变化。所以,变量名,直到我试图再次更新数据库,并发现了这种情况并非如此。