I'm trying to use SimpleMembership with MySQL in a Code First project. This is the initializer I made:
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 by AddUserToRole
:
Cannot add or update a child row: a foreign key constraint fails (
ticket
.webpages_usersinroles
, CONSTRAINTfk_RoleId
FOREIGN KEY (RoleId
) REFERENCESwebpages_roles
(RoleId
))
The user is added to the table userprofile
(and webpages_membership
) and the role to webpages_roles
. webpages_usersinroles
is still empty. MySQL can't reference the role because of a mysterious reason. How do I fix this issue?
Thanks in advance!