I am trying to use SimpleMembership with MySQL in a Code First project. This is the initializer I did:
WebSecurity.InitializeDatabaseConnection("MyConnectionStringName", "UserProfile", "UserId", "UserName", false);
if (!Roles.RoleExists("Employee"))
{
Roles.CreateRole("Employee");
}
if (!WebSecurity.UserExists("Kurt"))
{
WebSecurity.CreateUserAndAccount("Kurt", "test");
Roles.AddUserToRole("Kurt", "Employee");
}
The following exception appears in AddUserToRole:
Unable to add or update child line: foreign key constraint fails with error ( ticket. webpages_usersinroles, CONSTRAINT fk_RoleIdFOREIGN KEY ( RoleId) LINKS webpages_roles( RoleId))
The user is added to the table userprofile(s webpages_membership) and role webpages_roles. webpages_usersinrolesstill empty. MySQL cannot reference this role due to a mysterious reason. How to fix this problem?
Thanks in advance!
source
share