ASP.NET MVC 4 using the MySQL Simple Membership Provider (errno: 150)

I’ve been using the fairly new Simple Membership Provider (that ships with versions of the MySQL Connector/Net 6.9.0 and greater) for use with a new ASP.NET MVC 4 project.  However when following the tutorial for getting up and running from the MySql site ( https://dev.mysql.com/doc/connector-net/en/connector-net-simple-membership-tutorial-creating.html ). I ran into an issue when generating the webpages_* tables.

The specific error i received is: Can’t create table ‘.webpages_membership’ (errno: 150)

MySql Foreign Key Error

I have tried this multiple times using different configurations of visual studio and MySql server and the issue only seems to be with the MySql server version being too low, however the requirements never mention a specific minimum MySql server version number. Requirements can be found here ( https://dev.mysql.com/doc/connector-net/en/connector-net-simple-membership-tutorial-requirements.html )

However if you are using an older version of MySql server you can run the following script to generate the tables:

CREATE TABLE `webpages_membership` (
  `UserId` int(11) NOT NULL,
  `CreateDate` datetime DEFAULT NULL,
  `ConfirmationToken` varchar(128) DEFAULT NULL,
  `IsConfirmed` tinyint(1) DEFAULT '0',
  `LastPasswordFailureDate` datetime DEFAULT NULL,
  `PasswordFailuresSinceLastSuccess` int(11) NOT NULL DEFAULT '0',
  `Password` varchar(128) NOT NULL,
  `PasswordChangedDate` datetime DEFAULT NULL,
  `PasswordSalt` varchar(128) NOT NULL,
  `PasswordVerificationToken` varchar(128) DEFAULT NULL,
  `PasswordVerificationTokenExpirationDate` datetime DEFAULT NULL,
  PRIMARY KEY (`UserId`),
  CONSTRAINT `fk_User_Membership` FOREIGN KEY (`UserId`) REFERENCES `userprofile` (`UserId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `webpages_oauthmembership` (
  `Provider` varchar(30) NOT NULL,
  `ProviderUserId` varchar(100) NOT NULL,
  `UserId` int(11) NOT NULL,
  PRIMARY KEY (`Provider`,`ProviderUserId`),
  KEY `fk_UserId_OAuth_idx` (`UserId`),
  CONSTRAINT `fk_UserId_OAuth` FOREIGN KEY (`UserId`) REFERENCES `userprofile` (`UserId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `webpages_roles` (
  `RoleId` int(11) NOT NULL AUTO_INCREMENT,
  `RoleName` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`RoleId`),
  UNIQUE KEY `RoleName_UNIQUE` (`RoleName`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

CREATE TABLE `webpages_usersinroles` (
  `UserId` int(11) NOT NULL,
  `RoleId` int(11) NOT NULL,
  PRIMARY KEY (`UserId`,`RoleId`),
  KEY `fk_Role_idx` (`RoleId`),
  CONSTRAINT `fk_User` FOREIGN KEY (`UserId`) REFERENCES `userprofile` (`UserId`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_Role` FOREIGN KEY (`RoleId`) REFERENCES `webpages_roles` (`RoleId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `userprofile` (
  `UserId` int(11) NOT NULL AUTO_INCREMENT,
  `UserName` varchar(250) NOT NULL,
  PRIMARY KEY (`UserId`),
  UNIQUE KEY `UserName` (`UserName`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

 

Hope that helps.