使用SimpleMembership删除用户MVC 4时出错 [英] Error when deleting user mvc 4 using SimpleMembership
问题描述
当我尝试 Membership.DeleteUser(字符串,布尔)
在我使用 SimpleMembership
提供商MVC 4项目,我得到以下错误消息:
When I try Membership.DeleteUser(string, bool)
in a MVC 4 project where I use SimpleMembership
provider, I get following error message:
DELETE语句冲突与参考约束
fk_UserId。冲突发生于数据库Conductor_Basic3
表dbo.webpages_UsersInRoles,列用户ID。该语句
被终止。
"The DELETE statement conflicted with the REFERENCE constraint "fk_UserId". The conflict occurred in database "Conductor_Basic3", table "dbo.webpages_UsersInRoles", column 'UserId'. The statement has been terminated."
约束被设置,是正确的,所以我不能真正理解的错误消息。我想我已经错过了一些东西在这里。
The constraints is set and is correct, so I can't really understand the error message. I guess I've missed something here.
任何人都可以向我解释这个问题?
Can anyone explain to me this error?
推荐答案
看起来像表webpages_Roles有参考你的用户,你应该要排除的角色的用户,以后你能够删除用户,试试这个:
Looks like the table webpages_Roles has reference to your user, you should to exclude user from role, and after that you able to delete user, try this:
Roles.RemoveUserFromRole("UserName","RoleName");
Membership.DeleteUser("UserName");
或者你可以尝试用另一种方法:在你的数据库像这样明确地指定级联删除:
Or you can try to use another approach: explicitly specify cascade deletion in your db like this:
这篇关于使用SimpleMembership删除用户MVC 4时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!