I've trying the MVC 5.2 template with individual account. Everything works except when I trying to remove the user's login that I get the following error message:
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.
on the following line of ManagerController:
var result = await this.UserManager.RemoveLoginAsync(this.User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));
This is the complete RemoveLogin action:
[HttpPost] [Route("RemoveLogin")] [ValidateAntiForgeryToken] public async Task<ActionResult> RemoveLogin(string loginProvider, string providerKey) { ManageMessageId? message; var result = await this.UserManager.RemoveLoginAsync(this.User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey)); if( result.Succeeded ) { var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId()); if( user != null ) await this.SignInAsync(user, isPersistent: false); message = ManageMessageId.RemoveLoginSuccess; } else message = ManageMessageId.Error; return this.RedirectToAction("ManageLogins", new { Message = message }); }